Generating PDF in JavaScript – solutions

Generating PDF in JavaScript. A small set of solutions, that works both on client-side and server-side. Please just take a look.

Solutions for generating PDF in JavaScript

There are basically 3 solutions, that we’ve used.

1. jsPDF

JavaScript PDF generation – generate PDF files in client-side JavaScript.

Sample code:

var doc = new jsPDF();
doc.text(20, 20, 'Hello world.');'Test.pdf');

Check the GitHub page for more details and setup.

License: MIT.



Generating PDF in JavaScript? Sure!
Generating PDF in JavaScript? Sure!

2. pdfMake

Client- and server- side PDF printing in pure JavaScript! Some of features are:

– line-wrapping

– text-alignments (left, right, centered, justified)

– tables and columns

– col-spans and row-spans

– headers automatically repeated in case of a page-break

– images and vector graphics

– convenient styling and style inheritance

– page headers, footers, margins and background-layer

– page dimensions and orientations

– custom page breaks

– font embedding

– support for complex, multi-level (nested) structures


Simply add the resources:


vfs_fonts.js (default font definition)

We can get both files using bower:

bower install pdfmake

Sample JS:

var docDefinition = { 
  content: 'This is an sample PDF printed with pdfMake' 

// open the PDF in a new window

// download the PDF



The 3rd solution for generating PDF in JavaScript is PDF Kit.

3. PDFKit

A JavaScript PDF generation library for node.js, as well for browser.

PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable documents easy. It’s written in CoffeeScript.

Installation uses the npm package manager. Just type the following command after installing npm:

npm install pdfkit

Demo @ project homepage:



You may also like:

ClassyQR – generate QR code using jQuery

JavaScript Barcode Generator (JsBarcode)

jQuery progress indicator for table of contents

JavaScript table of contents generator – TocJS

Human readable file size in JavaScript

Upload files in JavaScript

Read files in JavaScript and HTML5