Closed
Description
Existing jsPDF plugins
Hi, I've been working on a new html2pdf package that uses html2canvas + jsPDF to convert HTML content to PDF. I know there are already three existing jsPDF plugins for HTML: addHTML
, fromHTML
, and html2pdf
(same name). I don't want to step on any toes - from what I can tell:
fromHTML
is the oldest plugin and renders the HTML directly to PDF (which is great), but its support for complex HTML/CSS is lacking.addHTML
is newer (but now deprecated) and uses html2canvas/rasterizeHTML to create a canvas, then puts the image onto the PDF page. Current state is described at How to get forward production with html2pdf / addHtml #944.html2pdf
: I haven't found much info (apart from the demo), but it looks like it renders directly to PDF likefromHTML
, which again is great but runs the risk of poor HTML/CSS support.
New html2pdf package
My html2pdf
package takes the same approach as addHTML
- I convert to a canvas with html2canvas, split that image up into pages, and attach each image onto its own PDF page. I believe it has some advantages over the jsPDF plugins:
- Easier to use - creating a PDF from an HTML element/page/string is one line:
html2pdf(element);
- Fits content to the page - it copies the HTML first into an (invisible) container div with the PDF page width, so that content can resize appropriately (also working on a 'shrink-to-page' option)
- Supports page-breaks - a feature that comes up a lot, i.e. Add automatic page breaks in HTML and text functions #190
- Is external - it keeps the logic separate and can respond more readily to updates in both repos (including html2canvas internally in jsPDF causes some problems)
- Is external (disadvantage) - it can't be used inline with other jsPDF commands the way the current plugins are - it's a standalone package that creates and closes the PDF.
Open issues
That said, I've found 48 open issues on jsPDF that I think html2pdf
could resolve, but I don't want to start pushing html2pdf
if it conflicts with jsPDF's internal implementations. @MrRio @Flamenco I'd appreciate your feedback!