A simple PDF export module for p5.js based on browser's print to pdf function.
See the further discussion here: https://github.com/processing/p5.js/issues/373
Examples (Please Use Google Chrome)
- Basic PDF Exporting
- Vector PDF Exporting
- Multiple pages using nextPage()
- Pause and Resume
- 4 columns * 3 rows per page and custom page size
- Custom filename, page margin, columnGap and rowGap
|Browser||Operating System||Print to PDF||Custom Size||Custom Filename|
|Firefox 39||Linux||Yes||Not programmatically, Buggy due to bug#851937||Not programmatically|
|IE9||Windows||Need Primo PDF||Not tested||Not tested|
|Safari||OS X||Not tested||Not tested||Not tested|
You can use p5.svg.
Include p5.svg and
createCanvas(640, 480, SVG).
Then the pdf generated will be vector.
Why not use jsPDF or pdfkit?
Seems that PDF doesn't support embed SVG difrectly. jsPDF's SVG support is buggy and very limited. I found that maybe using pdfkit is somehow better. But this library is also limited and may need a lot of work to make it work.
Since in most cases, we only need to export PDF for ourselves, so I think it is acceptable to use p5.SVG & window.print (print to pdf) to do this, since the browser's print function support vector by default and could work even the element was modified by third party library and this will avoid crashing due to creating large files in memory. BTW, browser's print support custom size (css3 @page) and filename (document.title) (test shows it works on chrome but buggy on firefox).