jsPDF
jsPDF copied to clipboard
Force Page Break Not Working
How to force Page Break. I used page-break-before: 'always' and page-break-after: 'always' . But nothing is working. I went through all stack overflow post but they all are waiting that some body will reply. Using this method doc.html()
I have 3 div.
Also experiencing the same issue. The examples in the repo indicate the page-break-before should work but it does not: https://github.com/parallax/jsPDF/blob/master/examples/html2pdf/page_break.html
Hi,
I finally resolve this. I manually set the height of each div to a4 size. If my div content is bigger than one page like 1 and half, I set the height of first div of 2 a4 size paper and rest one a4 size.
Here is ex:
const reportPage = document.getElementById('reportPage')
if (reportPage) {
const reportPageHeight = reportPage.offsetHeight
const reportPageHeightInPixel = Number(
reportPageHeight * 0.0264583333 // px to cm
)
const calcTotalPage =
Number(Math.ceil(reportPageHeightInPixel / 29.7) || 1) * 29.7
reportPage.style.minHeight = ${calcTotalPage}cm
}
Also experiencing the same issue. The examples in the repo indicate the page-break-before should work but it does not: https://github.com/parallax/jsPDF/blob/master/examples/html2pdf/page_break.html
This example is not work. And I can't use the style page-break-before: always to set the page break.
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
any solution founded ?
Sadly, this feature is completely broken in this library. I made it work using this library: https://github.com/eKoopmans/html2pdf.js which in turn uses jsPDF itself.
Sadly the other library is also not maintained anymore and has no TypeScript typings. But at least it works.