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.');
doc.save('Test.pdf');

Check the GitHub page for more details and setup.

License: MIT.

Demo:

https://parall.ax/products/jspdf

GitHub:

https://github.com/MrRio/jsPDF

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

Usage

Simply add the resources:

pdfmake.min.js

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
pdfMake.createPdf(docDefinition).open();

// download the PDF
pdfMake.createPdf(docDefinition).download();

Demo:

http://pdfmake.org

GitHub:

https://github.com/bpampuch/pdfmake

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:

http://pdfkit.org

GitHub:

https://github.com/devongovett/pdfkit

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

Enjoy!

Share:Share on Facebook1Share on Google+0Tweet about this on TwitterShare on LinkedIn1Pin on Pinterest1