HTML to PDF, calculate pagebreaks
Is it possible for the jsPDF to calculate pagebreaks when converting htmlcontent? I guess its not an easy task but if its just text in the HTML it should be possible to calculate when to do addpage, since the fontsize and papersize should be known.
Not an issue really but it would be great if this could be done.
+1
I've personally been working on generating and printing HTML, but just with the built-in print. You could use the CSS properties to get that paging, would also make it behave "somewhat" like the printing. http://davidwalsh.name/css-page-breaks
+1
+1
+1
According to the fromHTML plugin code you can insert to your html and it'll instruct a page break.
I am trying to use jsPDF with Datatables....Therefor it will ALWAYS be dynamic content. The option is obviously not usable. Is there anyway to get this to be done automagically?
Is there some marker within the PDF I need to look for? Is there something event wise from jsPDF I can look for? Help!
Sample loop to detect page, and continue writing data on next page.
var arrData = YOUR DATA RECORDS;
var doc = new jsPDF('landscape'); doc.setFontSize(10); for(var i = 0;i < arrData.length; i+=1) { line+=5; doc.text(5, line, arrData.name); if(line == 295) { doc.addPage(); line = 10; line += 5; doc.text(5, line, arrData.name); } }
Jspdf render blank pdf if it contains more number pages in it.. ex.. 35 pages pdf going blank.. any solution for this.
same issue here, on a greasemonkey script using jsPDF
I would also like to specify a page break when generating a pdf. I'm working with angularjs and I'm able to load dynamic content and subsequently generate a pdf from it, however, if I try using <!-- ADD_PAGE --> nothing happens. The program doesn't seem to be running a check for it in the first place. Anyone have any suggestions?
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.
var pdf = new jsPDF('p','pt','a4');
$(".rptContent").each(function() {
pdf.addHTML($(this).get(0), function(){
});
pdf.addPage();
});
pdf.save("plan.pdf");
I was doing the same, but no luck, 15 pages got created but all are blank. here ".rptContent" is div tag.
try #1450