0

Currently, I use html2pdf.js to generate PDFs using HTML, but I need a little more customisation. How can I create the same setup using jsPDF and, if necessary, html2canvas?

The following is my current setup:

async function downloadPDF() {
  const element = document.getElementById("report");

  const options = {
    image: { type: "jpeg", quality: 0.95 },
    html2canvas: { scale: 3 },
    jsPDF: {
      format: "a4",
      orientation: "portrait",
    },
    margin: [12, 0],
    pagebreak: { avoid: ".section", mode: "css" },
  };
  const fileName = "test_123"

  await html2pdf()
    .from(element)
    .set(options)
    .save(`${fileName}.pdf`);
}
  • 1
    Does this answer your question? [Generate pdf from HTML in div using Javascript](https://stackoverflow.com/questions/18191893/generate-pdf-from-html-in-div-using-javascript) – Justinas Jun 27 '23 at 13:09
  • @Justinas Thanks, I saw that answer, but unfortunately, .fromHTML is deprecated. I tried almost every guide I could find online, but I either generate a blank page or my content is so zoomed in that nothing is distinguishable. – Jeroen van der Merwe Jun 27 '23 at 13:23
  • Seems like it should be replaced with `.html()`: https://github.com/parallax/jsPDF/issues/2852 – Justinas Jun 27 '23 at 13:26

0 Answers0