According to PDFKit, it is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable documents easy. This module provides you with functionality like create a PDF document, add pages to it, writing text, adding graphics and images.
npm install pdfkit
Creating PDF Document Example :
var pdf = require('pdfkit');
var fs = require('fs');
var myDoc = new pdf;
.text('My First PDF using PDFKit', 100, 100);
Result : A output.pdf file is created with a text "My First PDF using PDFKit".
In the above example at first we have created a new PDF document by using the command var myDoc = new pdf; After that we have added a font named 'Times-Roman' with a font size of 50. Then the text is drawn at X, Y coordinates of 100, 100.
When using the example from the PDFKit Website you might get an error as Syntax error: Unexpected Identifier.
To solve this error you need to write fs.createStream() within the braces of myDoc.pipe() for ex : myDoc.pipe(fs.createWriteStream('output.pdf')); along with that you need to add var fs = require('fs').
To Play with the PDFKit, you can check An Interactive Browser Demo. Please Like and Share the Blog, if you find it interesting and helpful.