how to add hidden component while downloading pdf using react' code example

Example 1: pdf table files download react not working

let page = document.getElementById("divToPrint"); 
html2PDF(page, {
      jsPDF: { unit: "pt", format: "A4", orientation: "portrait" },
      imageType: "image/jpeg",
      output: "./pdf/generate.pdf",
    });

Example 2: pdf table files download react not working

let input = document.getElementById("divToPrint"); 

html2canvas(input)
  .then((canvas) => {
    const imgData = canvas.toDataURL('image/png');
    const pdf = new jsPDF();
    pdf.addImage(imgData, 'PNG', 0, 0);
    pdf.save("download.pdf");  
  });
;