How To Render PDF Documents With NODE.js

This tutorial gets you started learning how to render PDF with JavaScript and Node.js.Rendering PDF documents is a problem that you'll often need to solve when building web applications that deals with PDF files ,for example your applications may need to generate an invoice order as PDF for saving on hard disk or for printing .

Anyway working with PDF documents is a common problem developers need to be able to solve,so i introduce you to possible options that you can use to render PDF files with JavaScript and Node.js

Render PDF documents with PDFKit This library can be used to render PDF documents with ease,it works both on browser and on Node.js,you can create complex and multipages documents .If you are working with Node.js you can easily install via npm:

npm install pdfkit

Key features of this library are:

Work with Text

Work with vector graphics

Font and Image embedding


How to use PDFKit

PDFDocument = require('pdfkit');

Create a new document

doc = new PDFDocument(); Create your new document

Create a new PDF document

var doc = new PDFDocument();

Pipe its output to a file

doc.pipe(fs.createWriteStream('output.pdf')); You can create a page and add text with simple API and then finalize your doc

Add some text with annotations

doc.addPage() .fillColor("blue") .text('Here is a link!', 100, 100) .underline(100, 100, 160, 27, color: "#0000FF") .link(100, 100, 160, 27, '');

Finalize PDF file


For more information about PDFKit visit its official website here.

PDFKit is available free and open source under the MIT license .

As you can see that working with PDFKit is easy ,you can generate PDF documents with simple API and few lines of code.

comments powered by Disqus