It'd be helpful if we could calculate the end of a page with HTML rendering functions. This would have to take some kind of page margin.
+1
+1
+1
What would be an example of this? I'm wondering if this would solve a problem I have. I can't stand that the page breaks can occur right through some text. I'd love there to be a way to indicate in HTML where I'd prefer the page breaks to occur, like a custom attribute on an element.
For example, when splitting the canvas into separate images for a multiple page PDF, if the code could check the HTML for the existence of an element with the custom attribute within 300px from the bottom of what will be the next page, then use it's vertical position as the value for how tall the image should be on that page. If no attributes are found, make the image the size of the page as usual.
That way you could avoid having page breaks occur through content. I haven't looked through the code, so I don't know if this is possible, but it sure would be nice.
Lack of automatic page breaks in HTML is probably the only reason why we are not using this plugin. Would be great to have!
+1
+1
I'm copying this from another comment, but you can sort of do this:
For people coming here later trying to figure this out, the <!-- ADD_PAGE --> option no longer seems to exist. You have a couple of choices here now. You can add pagesplit to your options in the call to addHTML like so:
pdf.addHTML($(modalID).get(0), {pagesplit: true}, callback);
The pagesplit option will just break anywhere it pleases, which might be in the middle of a line of text so this might not be desirable in all cases. Alternatively, you can manually paginate your document by nesting the callback like so:
pdf.addHTML($(elementSelector).get(0), function(){
pdf.addPage();
pdf.addHTML($(differentElementSelector).get(0), function(){
pdf.save("plan.pdf");
});
});
I would suggest recursion if that gets too deep. The above will add an element, terminate the page, add another element, and then save the PDF in that state.
We are closing this issue, because we will not support any longer fromHTML and addHTML.
Explaination:
We are working on a new html2pdf plugin, which will be based on html2canvas and our context2d plugin. This should lead to more reliable results for your projects. And it will give us the time to focus on the core functionality of pdf-generation because we will not use our energy for writing/supporting/extending 2 html plugins. If you still want to use addHTML or fromHTML you can still use jsPDF 1.4.1.
Best Regards
Most helpful comment
I'm copying this from another comment, but you can sort of do this:
For people coming here later trying to figure this out, the
<!-- ADD_PAGE -->option no longer seems to exist. You have a couple of choices here now. You can addpagesplitto your options in the call toaddHTMLlike so:The
pagesplitoption will just break anywhere it pleases, which might be in the middle of a line of text so this might not be desirable in all cases. Alternatively, you can manually paginate your document by nesting the callback like so:I would suggest recursion if that gets too deep. The above will add an element, terminate the page, add another element, and then save the PDF in that state.