Tengo un html que contiene algunos encabezados y tablas. Aquí está mi código a continuación para convertir el html a pdf usando la biblioteca jspdf (referido desdehttps://www.freakyjolly.com/html2canvas-multipage-pdf-tutorial/ ).
var pdf,page_section,HTML_Width,HTML_Height,top_left_margin,PDF_Width,PDF_Height,canvas_image_width,canvas_image_height; function calculatePDF_height_width(selector,index){ page_section = document.querySelector(selector); HTML_Width = page_section.clientWidth; HTML_Height = page_section.clientHeight; top_left_margin = 15; PDF_Width = HTML_Width + (top_left_margin * 2); PDF_Height = (PDF_Width * 1.2) + (top_left_margin * 2); canvas_image_width = HTML_Width; canvas_image_height = HTML_Height; } function createPDFfromHTML() { let pdf = "" // report-content-2 is the section I want to get the pdf for html2canvas(document.querySelector("#report-content-2"), { allowTaint: true }).then(function(canvas) { calculatePDF_height_width("#report-content-2",2); var imgData = canvas.toDataURL("image/jpg", 1.0); pdf = new jsPDF('p', 'pt', [PDF_Width, PDF_Height]); pdf.addPage([PDF_Width, PDF_Height]); pdf.addImage(imgData, 'JPG', top_left_margin, top_left_margin, HTML_Width, HTML_Height); pdf.save("report.pdf"); }); };Pero todo lo que hace es obtener una sola página de contenido. En lugar de ir a varias páginas y obtener todo el contenido. También por alguna razón mantiene la primera página en blanco. El contenido aparece en la segunda página.
¿Cómo hago para que funcione de manera que obtenga el contenido completo en varias páginas?