Skip to content
Flamenco edited this page Dec 16, 2014 · 8 revisions

To use plugins, include them after the jsPDF script.

<script type="text/javascript" src="jspdf.js"></script>
<script type="text/javascript" src="jspdf.plugin.outline.js"></script>

or use require.js (recommended) with the included configuration script. This will pull in any dependencies.

<script src='js/libs/require/require.js'></script>

<script>
require(['js/libs/require/config'], function() {
    require(['jspdf.plugin.outline.js'], function() {
        // put your code here
    }); // require
}); // require
</script>

#Outline Create a PDF outline (bookmarks).

var pdf = new jsPDF('p', 'pt', 'letter');
pdf.text(20, 20, 'Hello');
pdf.addPage();
pdf.text(20, 20, 'PDF');
pdf.addPage();
pdf.text(20, 20, 'World');

var node = pdf.outline.add(null, 'Test Pages', null);
pdf.outline.add(node, 'Hello', {pageNumber:1});
pdf.outline.add(node, 'PDF', {pageNumber:2});
pdf.outline.add(node, 'World', {pageNumber:3});

#Annotations Currently only links to page numbers and external URLs are supported. Internal named links are also implemented. Popup and FreeText annotations have recently been added too.

var pdf = new jsPDF('p', 'pt', 'letter');
pdf.text(20, 20, 'Hello');

pdf.addPage();
var y = 20;
text = "Goto First Page";
pdf.textWithLink(text, 20, y, {pageNumber:1});
y += pdf.getLineHeight();    
          
text = "Goto External URL";
pdf.textWithLink(text, 20, y, {url:'http://www.twelvetone.tv'});

The link method will allow any page area to respond to a click (not just text).

pdf.link(20, 20, 50, 30, {pageNumber:1});

#context2d

Use the HTML5 Canvas context2d interface to create PDFs (see context2s Wiki Page)

Clone this wiki locally