A modular JavaScript library to create PDFs
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'
})
MIT