Is there any way to generate a dynamic pdf and download it, without rendering it using react

993 Views Asked by At

I am trying to generate a dynamic pdf, with some layout and it works fine, and I can download it too. But what I want is to download it without rendering it front-end. I am using @react-pdf/renderer for the same.

I tried using css property like display:"none" to accoplish it, but nothing seemed working. Is there any way make it work.

Note: I am trying to achieve it from front-end itself.

1

There are 1 best solutions below

0
On BEST ANSWER

Adding the answer for future reference,

This could be done with the pdf() method provided by @react-pdf/renderer.

  const downloadPdf = async () => {
    const fileName = 'test.pdf';
    const blob = await pdf(<YourDocument />).toBlob();
    saveAs(blob, fileName);
  };

For more details refer to this discussion