@react-pdf/renderer. How to generate PDF and download it

11,588

In case you face the same problem, I found something that help. Replace PDFViewer for the code below:

<PDFDownloadLink document={<FeeAcceptance />} fileName="fee_acceptance.pdf">
  {({ blob, url, loading, error }) => (loading ? 'Loading document...' : 'Download now!')}
</PDFDownloadLink>

https://react-pdf.org/components

Share:
11,588

Related videos on Youtube

Ronildo Braga Junior
Author by

Ronildo Braga Junior

Updated on June 04, 2022

Comments

  • Ronildo Braga Junior
    Ronildo Braga Junior about 2 years

    I managed to generate the pdf document and show it on the page but I am struggling to setup an option to download it.

    It is possible to setup something like click here to download the document?

    Please refer to the code below:

    import React, {Component} from 'react';
    import { PDFViewer } from '@react-pdf/renderer';
    import FeeAcceptance from '../Pdfgenerator/FeeAcceptance'
    
    class AcceptFees extends Component {
    
      render () {
          return (
              <>
                  <PDFViewer>
                      <FeeAcceptance member_detail={'test'} />
                  </PDFViewer >
    
                  <h1>click<a href="?????"> here </a>to download the document</h1>
              </>
          );
      }
    }
    
    export default AcceptFees;
    

    Thank you in advance.