Skip to content

Instantly share code, notes, and snippets.

@gr2m
Last active August 29, 2015 14:19
Show Gist options
  • Save gr2m/0754a2133472d2ba27ca to your computer and use it in GitHub Desktop.
Save gr2m/0754a2133472d2ba27ca to your computer and use it in GitHub Desktop.
var fs = require('fs')
var PDF = require('dream-pdf')
var tableData = require('./table.json')
PDF.plugin(require('dream-pdf-text'))
PDF.plugin(require('dream-pdf-image'))
PDF.plugin(require('dream-pdf-table'))
pdf = new PDF({
size: [210, 297]
})
pdf.text.loadFont('MyFunkyFont', fs.readFileSync('./path/to/funky.ttf'))
pdf.text.add("Hello, World", {
at: [20, 40],
size: 18
})
pdf.image.add(fs.readFileSync('./path/to/image.png'), {
at: [140, 40],
size: [60, 40]
})
pdf.table.add(tableData, {
at: [20, 120]
})
var data = pdf.toBlob()
// do what ever I want, like write to file, download, etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment