Skip to content

gr2m/dream-pdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dream-pdf

A modular JavaScript library to create PDFs

Build Status Coverage Status Dependency Status devDependency Status

NPM

Motivations

  • Create PDFs with the same APIs in both browsers and Node.js
  • Tiny core, many plugins
  • low barrier of entry for contributors (e.g. full test coverage)

API

var DreamPDF = require('dream-pdf')
var doc = new DreamPDF(/* options */)

doc.add('Hello, DreamPDF reader!')
doc.getContent(function(error, content) {
  // content can be written to file, or turned
  // into a data-url. It's out of scope for dream-pdf core.

  // Browser Example:
  // var dataUrl = 'data:application/pdf;base64,' + btoa(content)
  // Node Example:
  // fs.writeFileSync('my.pdf', new Buffer(content, 'binary'))
})

Plugins

By default, dream-pdf only supports adding text.

doc.add('Hello, PDF reader!')

Which is just a shortcut for

doc.add({ type: 'text', content: 'Hello, PDF reader!' })

To add other things than 'text' to your PDF, a plugin needs to be registered that handles the types.

// register new plugins
DreamPDF.plugin({
  'image': require('dream-pdf-image'),
  'password': require('dream-pdf-password')
})
// start new PDF and add objects with
// type matching the keys above
var doc = new DreamPDF(/* options */)
pdf.add({
  type: 'image',
  path: './path/to/image.png'
})
pdf.add({
  type: 'password',
  content: 'secret'
})

Resources

License

MIT

About

A modular JavaScript library to create PDFs

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published