score:2

Accepted answer

jspdf has a method to render html, you can use it instead of creating the document manually with images, this is the required change to your code:

   ...
   const input = document.getelementbyid("pdf-element");
   const pdf = new jspdf({ unit: "px", format: "letter", userunit: "px" });
   pdf.html(input, { html2canvas: { scale: 0.57 } }).then(() => {
     pdf.save("test.pdf");
   });
   ...

noticed that i tweak some configs in jspdf object creation and when calling .hmtl(), for some reason the pdf gets zoomed in, that's why i addded the scale option for html2canvas (this might as well be platform/browser dependant)

this is the fork with the changes https://codesandbox.io/s/react-table-to-pdf-forked-2iri9

score:0

you can use this code:

...
const input = document.getelementbyid("pdf-element");
const pdf = new jspdf('p', 'pt', 'a4');
    pdf.html(input).then(() => {
      pdf.save('test.pdf');
    });
...

Related Query

More Query from same tag