manniru
4/10/2015 - 7:41 PM

Example of using pdfkit in Node.js

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();