Skip to content

Instantly share code, notes, and snippets.

@officer-rosmarino
Created April 19, 2018 14:28
Show Gist options
  • Save officer-rosmarino/657d9e471e0cf54ea583d419375c2d66 to your computer and use it in GitHub Desktop.
Save officer-rosmarino/657d9e471e0cf54ea583d419375c2d66 to your computer and use it in GitHub Desktop.
Generate a PDF using pdfmake on the server with Node.js (no browser)
'use script'
var pdfmake = require('pdfmake');
var fs = require('fs');
const doc = new pdfmake({
Roboto: { normal: new Buffer(require('pdfmake/build/vfs_fonts.js').pdfMake.vfs['Roboto-Regular.ttf'], 'base64') }
}).createPdfKitDocument({ content: 'test' })
doc.pipe(fs.createWriteStream('myFile.pdf'))
doc.end()
@mozfet
Copy link

mozfet commented Apr 19, 2018

Unfortunately when I open the generated pdf on OSX using Adobe Acrobat I get an error.
screen shot 2018-04-19 at 17 21 59

When opening using PDF Preview of Chrome, no errors, but the doc is simply empty, as it is in Acrobat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment