Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
htmlToPdf issue with page breaks

I have a button that generates an html page once clicked. This is the code snippet of the onClick function

 const doc = new jsdpf('p', 'mm', 'a4');
 
 const downloadPdf = e => {
    e.preventDefault(); 
    htmlToImage
      .toPng(document.getElementById('divToPrint1'), { quality: 0.95 })
      .then(function (dataUrl) {
        var link = document.createElement('a');
        link.download = 'my-image-name.jpeg';
        const imgProps = doc.getImageProperties(dataUrl);
        var imgWidth = 210;
        var pageHeight = 295;
        var imgHeight = (imgProps.height * imgWidth) / imgProps.width;
        var heightLeft = imgHeight;
        var position = 10; 
        doc.addImage(dataUrl, 'PNG', 10, position, imgWidth, imgHeight);
        heightLeft -= pageHeight;
        while (heightLeft >= 0) {
          position += heightLeft - imgHeight; // top padding for other pages
          doc.addPage();

          doc.addImage(dataUrl, 'PNG', 0, position, imgWidth, imgHeight);
          heightLeft -= pageHeight;
        } 
        doc.save(`sample.pdf`);
      });
  };

the image is longer than an a4 thus new pages are generated but the issue is the image breaks just like this: image

Any idea what I can do to make the page not break this way?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!