jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

.html() page_break example not working

Open swildig opened this issue 5 years ago • 16 comments

The "page_break.html" example all displays on a single page with none of the expected breaks. I also tried "showcase_supported_html.html" and that exhibits similar issues.

I have tried using older versions of html2canvas and jsPDF but I can't find a combination that works.

Does anybody have a way to get these working?

Thanks,

swildig avatar Nov 11 '19 21:11 swildig

+1

I am unable to arrive at clean page breaking myself. Using html2canvas and jsPdf. Even tried the wrapper i've seen referenced a bunch, html2pdf.js, but that had issues of its own related to fitting the image proportionally... so i reverted back to the core libraries and dealing with no page break for now until I can put together a fix

ericfurspan avatar Dec 06 '19 04:12 ericfurspan

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 Jul 05 '20 01:07 github-actions[bot]

bump

benelliott avatar Jul 06 '20 08:07 benelliott

I confirm the issue

HanXHX avatar Aug 28 '20 15:08 HanXHX

I too confirm the issue

javitospfv avatar Feb 24 '21 17:02 javitospfv

i too having this issue

Karthik-PlantSense avatar Mar 19 '21 08:03 Karthik-PlantSense

I'm also facing the same issue. any update for this?

krupapanchal avatar Dec 02 '21 04:12 krupapanchal

bump... this is a big issue.

pagegwood avatar Dec 08 '21 17:12 pagegwood

I have this issue

rajorpratyush avatar Dec 31 '21 21:12 rajorpratyush

Still facing this, anyone found a workaround?

JetJacobs avatar Jul 08 '22 20:07 JetJacobs

I also have this issue :disappointed:

doublethink13 avatar Aug 24 '22 14:08 doublethink13

I'm also facing this issue

AnthonyPhan avatar Oct 16 '22 09:10 AnthonyPhan

Same issue 😢

jmalStorm avatar Oct 28 '22 07:10 jmalStorm

Same issue here in 2023. Any way to add explicit page breaks in jsPdf.html()?

blerrgh avatar Jun 06 '23 05:06 blerrgh

I confirm the issue

YuFengDing avatar Jun 19 '23 09:06 YuFengDing

Hi everyone,

I have done this funtion for A4 that calculates the margin to be added, seems to be working but probably not perfect:

In order to add a new page, just add

<div class='new-page'></div> 

or just the class in an element

<script>


       window.jsPDF = window.jspdf.jsPDF;

       function getOffset(el) {
           const rect = el.getBoundingClientRect();
           return {
               left: rect.left + window.scrollX,
               top: rect.top + window.scrollY
           };
       }

       var htmlElement = document.getElementById("html");
       var htmlElementY = getOffset(htmlElement).top;
       //Page height - margin bottom
       var pageHeight = 805.75 - 40;
       var els = document.getElementsByClassName("new-page");




       Array.prototype.forEach.call(els, function (el) {
           var elementY = getOffset(el).top;
           var addPoints = pageHeight - ((elementY - htmlElementY) % pageHeight);
           console.log(elementY, htmlElementY, addPoints);
           el.style.marginTop = addPoints + "px";
       });


       var pdf = new jsPDF('p', 'pt', 'a4');


       pdf.html(document.getElementById('html'), {
           margin: [40, 60, 40, 60],
           callback: function (pdf) {
               addFooters(pdf)
               pdf.save('web.pdf');
           }
       });

       const addFooters = doc => {
           const pageCount = doc.internal.getNumberOfPages()
           console.log(doc.internal.pageSize.width, doc.internal.pageSize.height);
           doc.setFontSize(8)
           for (var i = 1; i <= pageCount; i++) {
               doc.setPage(i)
               doc.text('Página ' + String(i) + ' de ' + String(pageCount), doc.internal.pageSize.width / 2, 820, {
                   align: 'center'
               })
           }
       }

   </script>

cmorillo avatar Jun 21 '23 07:06 cmorillo