1

I'm trying to convert my HTML Element into PDF and download it like what normal browsers do.

This is what I did

 const onGeneratePdf = () => {
    const input = document.getElementById('divToPrint')!;
    const { clientWidth, clientHeight } = input;

    html2canvas(input, {
      width: clientWidth,
      height: clientHeight,
    }).then((canvas) => {
      const imgData = canvas.toDataURL('image/png');
      const pdf = new jsPDF('p', 'px', [clientWidth, clientHeight]);

      pdf.addImage(imgData, 'PNG', 0, 0, clientWidth, clientHeight);
      pdf.save("download.pdf");
    });
  }

This code works perfectly on a browser, but it didn't work on a Tauri App. The question is, how can I make it work on a Tauri app? or is there any alternative that I can use with similar function?

Dylan
  • 1,121
  • 1
  • 13
  • 28

0 Answers0