Hi I have a few questions regarding the use of html2canvas. I am learning JavaScript and I am making a platform that helps to provide budgets that are downloaded in PDF format. I need the html2canvas to take a section (id=imagenPiezas) which is dynamicaly populated through a script (in index.js takes the ids and imgs from a data.js) and take it to pdf-lib. The result is that when I generate the PDF, the section (id=imagenPiezas) that needs to be included doesn't appear in the PDF.
To contextualize this problem, the main idea of the project is the following: Is an inside site to facilitate the budget making of the company, there are different inputs and the input id=piezas1-8 allows the user to select different pieces from a couch to make your configuration. In the section id=imagenPiezas you are going to see the couch configuration dynamically changing. The idea is that the html2canvas takes and img of that section an prints it into the PDF (pdfgenerator.js).
GITHUB LINK: https://github.com/FrancoKohler/Temasdos
I tried a wide variety of things, the main one in which i have been working around was this one (but in what I have tried that html2canvas isnt correctly printing it on the PDF):
if (typeof html2canvas === "function") {
const canvas = await html2canvas(document.getElementById("imagenPiezas"));
const imgData = canvas.toDataURL("image/png");
const pdfImage = await pdfDoc.embedPng(imgData);
page.drawImage(pdfImage, { x: 20, y: 160, width: 170, height: 100 });
} else {
console.error("html2canvas is not loaded correctly.");
}