Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

81
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda