JavaScript PDF Generation

2010-01-26 00:00:00 +0000 by Alex R. Young

I searched for JavaScript PDF generation just to see what server-side
technologies are available. I found
jsPDF, which works both server-side and in browser. It currently works best in Safari, Firefox 3+ and Opera.

It uses the data URI
to send the data
to the browser, which is a problem for IE.

The code is easy to follow -- if you want to learn about PDF generation
it's interesting to read through. There's a demo
usage examples and the resulting PDFs.

Usage looks like this:

var doc = new jsPDF();
doc.text(20, 20, 'Hello world!');
doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
doc.text(20, 20, 'Do you like that?');

// Output as Data URI

jsPDF doesn't have many options yet -- fonts are hardcoded for example
(to helvetica). It's an interesting demonstration of the power of client-side programming though.