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

386
Visualizações
How do I fit the entire content in one page when printing it to PDF?

I am using jspdf and html2canvas. Printing the component would make the footer go to the next page.

How can I set this where it will dynamically resize to fit it on one page when I print it to pdf? Is this possible where the entire component will fit in one page only?

     const generatePdf = () => {
    var doc = new jsPDF("portrait", "pt", "a4");

    doc.html(document.querySelector("#pdf"), {
      html2canvas: {
        scale: 0.5
      },
      callback: function (pdf) {
        pdf.save(`sample.pdf`);
      }
    });
  };
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Could you try this, may not be the best solution. Also, note that this will render the HTML as an image and not as text/vector graphics.

const quality = 1 // Higher Quality results in better output
html2canvas(document.querySelector('#html'),
    { scale: quality }
).then(canvas => {
    const pdf = new jsPDF('p', 'mm', 'a4');
    pdf.addImage(canvas.toDataURL('image/png'), 'PNG', 0, 0, 211, 298); // Play around with the metrics here to your liking
    pdf.save(filename);
});

Follow this discussion on GitHub for a better understanding.

about 4 years ago · Juan Pablo Isaza Relatório
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