Necesito imprimir imágenes en varios tamaños y no puedo entender por qué el resultado de mi variable imgHeight a veces tiene valores diferentes.
Este es el método que estoy usando para procesar el 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; } },Así es como debería verse mi pdf
Y esto es lo que sucede A VECES
La imagen del segundo plano debe estar debajo de la primera y no a la izquierda como se muestra. Se trata de dos estampados diferentes con el mismo código.