Tengo un botón que genera una página html una vez que se hace clic. Este es el fragmento de código de la función onClick
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`); }); }; la imagen es más larga que un a4, por lo que se generan nuevas páginas, pero el problema es que la imagen se rompe así: 
¿Alguna idea de lo que puedo hacer para que la página no se rompa de esta manera?