Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 317
Ronildo Braga Junior Avatar asked May 17 '19 06:05

Ronildo Braga Junior


Video Answer


1 Answers

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

like image 164
Ronildo Braga Junior Avatar answered Sep 28 '22 06:09

Ronildo Braga Junior