A modular JavaScript library to create PDFs
- 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)
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'))
})
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'
})
- Official specifications: https://www.adobe.com/devnet/pdf/pdf_reference_archive.html
- Twitter thread with great slide decks and cheat sheets: https://mobile.twitter.com/angealbertini/status/1194219247112785920
MIT