MatthewHerbst / react-to-print

Print React components in the browser. Supports Chrome, Safari, Firefox and EDGE
MIT License
2.06k stars 221 forks source link

getting Supplied Data is not a valid base64-String jsPDF.convertStringToImageData erorr while directly downloading image #694

Closed mayurbrainvire closed 5 months ago

mayurbrainvire commented 6 months ago
  const handleDownload = useReactToPrint({
    content: () => componentRef?.current,
    removeAfterPrint: true,
    pageStyle: pageStyle,
    print: async (printIframe) => {
      const document = printIframe?.contentDocument;
      if (document) {
        const html = componentRef?.current;
        const exporter = new html2pdf(html, {
          filename: "candidates.pdf",
          image: { type: "jpeg", quality: 1 },
          html2canvas: { scale: 1, useCORS: true },
          jsPDF: { format: "A4" },
        });
        exporter.getPdf(true);
      }
    },
    copyStyles: true,
  });

   <ReactToPrint
        // content={reactToPrintContent} // for preview and download
        content={handleDownload}
        documentTitle="candidates"
        trigger={reactToPrintTrigger}
        pageStyle={pageStyle}
        onBeforeGetContent={handleOnBeforeGetContent}
      />
MatthewHerbst commented 6 months ago

Hello. This seems like an issue with html2pdf. What makes you believe there is a problem with react-to-print?