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

256
Visualizações
jsPDF - why my pdf print sometimes shrinks?

I need to print images in various sizes, and I can't understand why the result of my variable imgHeight sometimes has different values.

This is the method I'm using to process the pdf

 async addImageToPdf(elementId: string) {
  const thumbnailsHtml = document.getElementById(elementId) as HTMLElement;
  await this.sleep(500);
  const canvas = await html2canvas(thumbnailsHtml, { useCORS: true });
  const imgData = canvas.toDataURL("image/jpeg", 1.0);
  await this.sleep(500);
  const imgProps = this.pdf.getImageProperties(imgData);
  const pdfWidth = 210 /* this.pdf.internal.pageSize.getWidth() */;
  const pageHeight = this.pdf.internal.pageSize.getHeight() + 40;
  const imgHeight = (imgProps.height * pdfWidth) / imgProps.width;
  console.log(imgProps);
  console.log(imgHeight);
  var heightLeft = imgHeight;
  var position = 0;

  this.pdf.addImage(
    imgData,
    "JPEG",
    15, // Position of image from left and right
    10, // Position of image from top and bottom
    pdfWidth,
    imgHeight
  );

  heightLeft -= pageHeight;
  while (heightLeft >= 0) {
    position = heightLeft - imgHeight;
    this.pdf.addPage();
    this.pdf.addImage(
      imgData,
      "JPEG",
      5,
      position + 52,
      pdfWidth,
      imgHeight
    );
    heightLeft -= pageHeight;
  }
},

This is what my pdf should look like

enter image description here

And this is what happens SOMETIMES

enter image description here

The second plan image should be below the first one and not in the left like it shows. These are two different prints with the same code.

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