jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

Force Page Break Not Working

Open sudhirroy1994 opened this issue 3 years ago • 3 comments

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.

.......
-----------Page Break------------ Force Page Break
.......
-----------Page Break------------ Force Page Break
.......

sudhirroy1994 avatar Sep 23 '22 21:09 sudhirroy1994

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

AnthonyPhan avatar Sep 30 '22 06:09 AnthonyPhan

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 }

sudhirroy1994 avatar Sep 30 '22 09:09 sudhirroy1994

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.

zhouwei99 avatar Oct 09 '22 09:10 zhouwei99

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.

github-actions[bot] avatar Jan 08 '23 02:01 github-actions[bot]

any solution founded ?

ChamkhiAnas avatar Jan 31 '23 17:01 ChamkhiAnas

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.

JonasDoesThings avatar May 03 '23 13:05 JonasDoesThings