jsPDF Demos

Examples for using jsPDF with Data URIs below. Go back to project homepage.

Simple Two-page Text Document

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

// Making Data URI
var out = doc.output();
var url = 'data:application/pdf;base64,' + Base64.encode(out);
document.location.href = url;
Run Code

Different font sizes

doc = new jsPDF();
doc.addPage();
doc.setFontSize(22);
doc.text(20, 20, 'This is a title');

doc.setFontSize(16);
doc.text(20, 30, 'This is some normal sized text underneath.');	

// Making Data URI
var out = doc.output();
var url = 'data:application/pdf;base64,' + Base64.encode(out);
document.location.href = url;
Run Code

Adding metadata

doc = new jsPDF();
doc.addPage();
doc.text(20, 20, 'This PDF has a title, subject, author, keywords and a creator.');

// Optional - set properties on the document
doc.setProperties({
	title: 'Title',
	subject: 'This is the subject',		
	author: 'James Hall',
	keywords: 'generated, javascript, web 2.0, ajax',
	creator: 'MEEE'
});

// Making Data URI
var out = doc.output();
var url = 'data:application/pdf;base64,' + Base64.encode(out);
document.location.href = url;
Run Code