Skip to content

Instantly share code, notes, and snippets.

@boanergepro
Forked from danawoodman/pdf.js
Created September 14, 2017 14:08
Show Gist options
  • Save boanergepro/20aa0834125cc2306473933262f9bb94 to your computer and use it in GitHub Desktop.
Save boanergepro/20aa0834125cc2306473933262f9bb94 to your computer and use it in GitHub Desktop.
Example of using pdfkit in Node.js
var fs = require('fs');
var PDFDocument = require('pdfkit');
var pdf = new PDFDocument({
size: 'LEGAL', // See other page sizes here: https://github.com/devongovett/pdfkit/blob/d95b826475dd325fb29ef007a9c1bf7a527e9808/lib/page.coffee#L69
info: {
Title: 'Tile of File Here',
Author: 'Some Author',
}
});
// Write stuff into PDF
pdf.text('Hello World');
// Stream contents to a file
pdf.pipe(
fs.createWriteStream('./path/to/file.pdf')
)
.on('finish', function () {
console.log('PDF closed');
});
// Close PDF and write file.
pdf.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment