Canvas2PDF exports an HTML canvas to PDF. In other words, this library lets you build a PDF documentusing the canvas API.
How it works
Dec 22, 2017 Generating PDF file format in client-side JavaScript is now trivial with a great library we have probably heard of. The library allows you to select the DOM (Document Object Model) elements that you wish to publish as PDF content. Exporting generic HTML/CSS to PDF has been an open question without a definitive answer for quite a long time.
We create a mock 2d canvas context. Use the canvas context like you would on a normal canvas. As you call methods, weuse PDFKit to generate a PDF document.
Browser Usage
Node Usage
Dependencies
- blob-stream required when using in a web browser.
Using with node.js
canvas2pdf
works with node.js. Note that neither a DOM or canvas library is needed.Html Canvas Pdf
Interactive Browser Demo
Notes
- Inspired by Canvas2Svg
- Calling fill and then stroke consecutively only executes fill
- Some canvas 2d context methods are not implemented yet (e.g. setTransform and arcTo)
Status
License
MIT
- Ghostscript and GraphicsMagick are required for running tests