Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
Unable to get multi page PDF from HTML using JsPDF?

I have an html which contains some headers and tables. Here is my code below to convert the html to pdf using jspdf library (referred from https://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");
       
           
    });
};

But all it does is gets a single page worth of content. Instead of going multi page and get all the content. Also for some reason it keeps the first page blank. The content shows up on second page.

How do I make it work such that I get the full content spanned across multiple pages?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda