jsPDF
jsPDF copied to clipboard
html() function always starts on first page
Hello. Does jsPDF.html method can draw <table> in pdf?
And how can i with html() draw in not first page of pdf?
Yes, html can draw tables.
Just call addPage/setPage before html.
I was try, but can't draw html on second page: https://jsitor.com/OjADPcBNh
Ah, you're right. There seems to be a bug in jsPDF. The context2d.autoPaging property is set to true (which is probably good for most use cases):
https://github.com/MrRio/jsPDF/blob/cef97fb34eda41a8704c9f3983e680919a328ce4/src/modules/html.js#L451-L454
However, the autoPaging mechanism doesn't respect the starting page. See e.g. here:
https://github.com/MrRio/jsPDF/blob/cef97fb34eda41a8704c9f3983e680919a328ce4/src/modules/context2d.js#L1675-L1681
A workaround would be to first call html with only one page and the afterwards add another page with insertPage before the first page.
Hi, any update regarding this issue? I've been facing the same issue.. Trying to add some html content after a table in the first few pages.. But the html content always starts from the first page on top of the table contents.
Hi, any update regarding this issue? I've been facing the same issue.. Trying to add some html content after a table in the first few pages.. But the html content always starts from the first page on top of the table contents.
While issue not fixed, i use offset by y coord:
doc.html(mdDiv,
{
callback: function (doc) {doc.save(); },
y: ((pageNum-1) * pageHeight) + offsetY,
});
i want to work on this issue
Hey, is this issue still valid? If so, is there a way to get a new repro link? Looks like the old link was removed (returning 404 now). I tried working on it but would be very nice to help me understand the issue and confirm it's all working once fixed.
I'm still experiencing this issue in the most recent version of jspdf, though I can't offer a repro at the moment. The workaround of https://github.com/parallax/jsPDF/issues/3204#issuecomment-888925112 worked for me.
The only way I found to re-execute the html function was to place the y from the height of the document. Note: you must take into account in the formula to calculate the Y, subtract the margins of the first html from the height. For example:
pdf.html(htmlContent,
callback: (doc) => {
doc.html(htmlContent2, {
y: (doc.internal.pageSize.getHeight() - MARGIN)* doc.getNumberOfPages() - 1,
callback: (doc) => {
window.open(doc.output("bloburl"));
},
});
},
});