Get started creating PDF file with Node and PDFKit.


$ npm install pdfkit --save

PDF Creation


Import the library and create the pdfKit document

var PDFDocument, doc;
var fs = require('fs');

PDFDocument = require('pdfkit');

doc = new PDFDocument;


// PDF Creation logic goes here


Insert some text

// Set a title and pass the X and Y coordinates
doc.fontSize(15).text('Wally Gator !', 50, 50);

// Set the paragraph width and align direction
doc.text('Wally Gator is a swinging alligator in the swamp. He\'s the greatest percolator when he really starts to romp. There has never been a greater operator in the swamp. See ya later, Wally Gator.', {
width: 410,
align: 'left'

Check out the documentation for more options, including fonts, colors, text decorations and more !

Insert an image

doc.image('wally.jpg', 50, 150, {width: 300});


Run the script as usual with

$ node index.js

And open the output.pdf file. You can check my result here. Once again, don’t forget to check out the official documentation for more examples and information.