0
I’m generating PDF with jspdf
and do the screenshot with the canvas
. The form
which generates the PDF is very large and generates more than one page.
Code:
window.html2canvas = html2canvas;
function demoFromHTML() {
const html_source = document.getElementById('employee_detail');
const filename = 'PIC.pdf';
html2canvas(html_source).then(function(canvas) {
let imgData = canvas.toDataURL('image/png');
let imgWidth = 210;
let pageHeight = 297;
let imgHeight = canvas.height * imgWidth / canvas.width;
let heightLeft = imgHeight;
let position = 0;
let pdf = new jsPDF('p', 'mm');
let fix_imgWidth = 0;
let fix_imgHeight = 18;
pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
heightLeft -= pageHeight;
while (heightLeft >= 0) {
position = heightLeft - imgHeight;
pdf.addPage();
pdf.addImage(imgData, 'PNG', 0, position, imgWidth + fix_imgWidth, imgHeight + fix_imgHeight);
heightLeft -= pageHeight;
}
pdf.save(filename);
})
}
The problem is that when I file the pdf on the pc, it breaks the page correctly, but when I generate the pdf on my phone it already breaks the page incorrectly. How can I put my code in order to adjust the page break always correct regardless of the screen size?
I leave the link to view the page break on your phone: insert link description here
Here I leave the link of the same pdf on computer: insert link description here
I wanted you to print where to print and adjust the document to the equipment screen automatically.
on the phone continues without making the correct page break.
– Bruno
My dear young man, you must change your values
fix_imgHeight
andfix_imgWidth
according to screen resizing. Uses browser emulator to simulate various device types. Open emulator in Chrome:CTRL
+SHIFT
+I
and thenCTRL
+SHIFT
+M
and in Firefox:Ctrl
+Shift
+M
– Cristiano Gilberto João
After a lot of tests, to function, I can’t use the modal. With modal, I could never get the result I wanted with this solution and with others I tried to test in various ways.
– Bruno