hey @geeky01adarsh, I believe you just don't want to display it right? In that case, you could use the @react-pdf/renderers pdf method and the file-saver package to achieve this.
import React from 'react'; import { saveAs } from 'file-saver'; import { pdf } from '@react-pdf/renderer'; import YourDocument from './YourDocument'; const DownloadButton = () => { const downloadPdf = async () => { const fileName = 'test.pdf'; const blob = await pdf(<YourDocument />).toBlob(); saveAs(blob, fileName); }; return <button onClick={downloadPdf}>Download PDFbutton>; }; export default DownloadButton;
this will convert your pdf component into a Blob and then saves it using saveAs method from file-saver
GitHub
github.com › diegomura › react-pdf › issues › 975
download pdf on custom button click · Issue #975 · diegomura/react-pdf
August 13, 2020 - diegomura / react-pdf Public · There was an error while loading. Please reload this page. Notifications · You must be signed in to change notification settings · Fork 1.3k · Star 16.5k · New issueCopy link · New issueCopy link · Closed · #1902 · Closed · download pdf on custom button click #975 ·
Author pradeepn541
How to render AND download on link clink, without rendering on page load
I have an application that generates a pdf based on the current state of the application when the user clicks a button. I'd like to use react-pdf, but I'm not sure how to make it work, since the default behavior seems to be to generate the pdf on page load and then only download it when the ... More on github.com
PDFDownloadLink does not create href in the Download button
My code works like charm in the dev box, but after deploying it to the prod box, I see a "TypeError: a is not a function", Not sure what this means and need help. Attached the error image. using "@... More on github.com
html - Download file by clicking a button in ReactJS - Stack Overflow
I have a website built with ReactJS and there are some files (PDF,DOC etc) that I want to let visitors download. But simple href tag doesn't start the download, instead refresh the page. More on stackoverflow.com
Generate PDF on the fly
This is what I am trying to solve currently and wondering if it is/will be possible with react-pdf: I need to be able to generate loads of different PDFs in our platform and would love to do that fully on the frontend. The user clicks download button which allows him to download a generated ... More on github.com
Videos
06:23
download as PDF button in React; pdf download button in react - ...
05:58
Download Pdf File In React - YouTube
08:16
How to download files in React JS | Download file instead of ...
13:03
How to create and download PDF file using React.js - YouTube
21:01
How to Export to PDF in React: Methods | React PDF Generator Part ...
43:11
How to create a PDF file using React.js - YouTube
Top answer 1 of 3
35
I have found below in their site documentation
import { PDFDownloadLink, Document, Page } from '@react-pdf/renderer'
const MyDoc = () => (
<Document>
<Page>
// My document data
</Page>
</Document>
)
const App = () => (
<div>
<PDFDownloadLink document={<MyDoc />} fileName="somename.pdf">
{({ blob, url, loading, error }) => (loading ? 'Loading document...' : 'Download now!')}
</PDFDownloadLink>
</div>
)
2 of 3
9
hi its working fine for me
import React from 'react';
import logo from './logo.svg';
import './App.css';
import { PDFDownloadLink, Page, Text, View, Document, StyleSheet } from '@react-pdf/renderer';
const styles = StyleSheet.create({
page: {
flexDirection: 'row',
backgroundColor: '#E4E4E4'
},
section: {
margin: 10,
padding: 10,
flexGrow: 1
}
});
const MyDoc = () => (
<Document>
<Page size="A4" style={styles.page}>
<View style={styles.section}>
<Text>Section #1</Text>
</View>
<View style={styles.section}>
<Text>Section #2</Text>
</View>
</Page>
</Document>
);
function App() {
return (
<div className="App">
<PDFDownloadLink document={<MyDoc />} fileName="somename.pdf">
{({ blob, url, loading, error }) => (loading ? 'Loading document...' : 'Download now!')}
</PDFDownloadLink>
</div>
);
}
export default App;
GitHub
github.com › ivmarcos › react-to-pdf
GitHub - ivmarcos/react-to-pdf: Generate pdf from react components · GitHub
import { usePDF } from 'react-to-pdf'; const Component = () => { const { toPDF, targetRef } = usePDF({filename: 'page.pdf'}); return ( <div> <button onClick={() => toPDF()}>Download PDF</button> <div ref={targetRef}> Content to be generated to PDF </div> </div> ) } Stackblitz demo ·
Starred by 341 users
Forked by 68 users
Languages TypeScript 86.4% | Shell 7.1% | JavaScript 5.5% | HTML 1.0%
GitHub
github.com › diegomura › react-pdf › issues › 2634
PDFDownloadLink does not create href in the Download button · Issue #2634 · diegomura/react-pdf
February 12, 2024 - import { PDFDownloadLink, Document,View, Text, Page } from '@react-pdf/renderer'; <Document> <Page> <View> <Text>test doc</Text> </View> </Page> </Document> PDFDownloadLink in another component: <PDFDownloadLink document={} fileName="somename.pdf"> {({ blob, url, loading, error }) => loading ? 'Loading document...' : 'Download now!'
Author vikasdinavahi
React-pdf
react-pdf.org › advanced
React-pdf
import { usePDF, Document, Page } from '@react-pdf/renderer'; const MyDoc = ( <Document> <Page> // My document data </Page> </Document> ); const App = () => { const [instance, updateInstance] = usePDF({ document: MyDoc }); if (instance.loading) return <div>Loading ...</div>; if (instance.error) return <div>Something went wrong: {instance.error}</div>; return ( <a href={instance.url} download="test.pdf"> Download </a> ); }
Top answer 1 of 8
23
The following approach worked for me.
import ExampleDoc from '......src/assets/files/exampleDoc.pdf'
<a href={ExampleDoc} download="MyExampleDoc" target='_blank'>
<Button className={classes.navLink}>My Example Doc</Button>
</a>
2 of 8
11
Try this:
const DownloadButton = props => {
const downloadFile = () => {
window.location.href = "https://yoursite.com/src/assets/files/exampleDoc.pdf"
}
return (
<button onClick={downloadFile} />
)
}
export default DownloadButton;
npm
npmjs.com › package › react-pdf
react-pdf - npm
February 25, 2026 - React-PDF is under constant development. This documentation is written for React-PDF 10.x branch. If you want to see documentation for other versions of React-PDF, use dropdown on top of GitHub page to switch to an appropriate tag.
» npm install react-pdf
Published Feb 25, 2026
Version 10.4.1
Author Wojciech Maj
Repository https://github.com/wojtekmaj/react-pdf
GitHub
github.com › diegomura › react-pdf › issues › 84
Generate PDF on the fly · Issue #84 · diegomura/react-pdf
May 30, 2017 - This is what I am trying to solve currently and wondering if it is/will be possible with react-pdf: I need to be able to generate loads of different PDFs in our platform and would love to do that fully on the frontend. The user clicks download button which allows him to download a generated ...
Published May 30, 2017
Author knowbody
GitHub
github.com › diegomura › react-pdf › issues › 957
How to generate multiple pdf on a click of button and download it as zip · Issue #957 · diegomura/react-pdf
July 26, 2020 - How to generate multiple pdf on client side using react pdf and when the download gets complete of all the files it should download it as a zip . This operation should be performed on client side o...
Author Akshaykapadi
Freddydiengott
freddydiengott.com › blogs › pdf-react
Downloading (and displaying) PDFs in React
November 20, 2024 - We have a PDF that we can download, albeit a simple one, but as it stands, to develop the PDF we would need to click the button and download our file over and over again after any change we want to see. Not ideal. So, to make this better we are going to use PDFViewer from @react-pdf/renderer to display the PDF.
GitHub
github.com › diegomura › react-pdf › issues › 533
Better examples to implement react-pdf, specifically downloading pdf or opening in browser · Issue #533 · diegomura/react-pdf
March 16, 2019 - Specifically, my problem is I would like a button that generates the pdf of a component. But, here is the recommended code from the doc: import { PDFDownloadLink, Document, Page } from '@react-pdf/renderer' const MyDoc = ( <Document> <Page> // My document data </Page> </Document> ) const App = () => ( <div> <PDFDownloadLink document={MyDoc} fileName="somename.pdf"> {({ blob, url, loading, error }) => (loading ? 'Loading document...' : 'Download now!')} </PDFDownloadLink> </div> )
Author foureyedraven
GitHub
github.com › diegomura › react-pdf
GitHub - diegomura/react-pdf: 📄 Create PDF files using React
📄 Create PDF files using React. Contribute to diegomura/react-pdf development by creating an account on GitHub.
Starred by 16.5K users
Forked by 1.3K users
Languages TypeScript 84.2% | JavaScript 15.7%
Stackademic
stackademic.com › blog › downloading-a-react-component-as-pdf-12021aaf0ccc
Downloading React Components as PDF Files | Stackademic
December 6, 2023 - You probably will not need this and things can break, // so use with caution. overrides: { // see https://artskydj.github.io/jsPDF/docs/jsPDF.html for more options pdf: { compress: true }, // see https://html2canvas.hertzen.com/configuration for more options canvas: { useCORS: true } }, }; // you can use a function to return the target element besides using React refs const getTargetElement = () => document.getElementById('content-id'); const Component = () => { return ( <div> <button onClick={() => generatePDF(getTargetElement, options)}> Generate PDF </button> <div id="content-id"> Content to be generated to PDF </div> </div> ); }
DEV Community
dev.to › jaymeeu › how-to-generate-custom-pdf-using-react-and-react-pdf-6d4
How to Generate Custom PDF, Using React and React-PDF. - DEV Community
February 12, 2024 - The image below shows the screenshot of a sample PDF invoice we will design for this project. The image below shows a preview of this project. Each invoice sample has download, print, and share buttons. ... Basic knowledge of JavaScript and ReactJS. Knowledge of CSS Flexbox property. The source code of the project is available on GitHub...
GitHub
github.com › diegomura › react-pdf › issues › 736
PDFDownloadLink should generate pdf on click · Issue #736 · diegomura/react-pdf
October 14, 2019 - Describe alternatives you've considered I've used pdf() function to generate the blob and file-saver lib to download it: import { saveAs } from 'file-saver'; import { pdf } from '@react-pdf/renderer'; import PdfDocument from '../PdfDocument'; const generatePdfDocument = async (documentData) => { const blob = await pdf(( <PdfDocument title='My PDF' pdfDocumentData={documentData} /> )).toBlob(); saveAs(blob, fileName); }; export default generatePdfDocument;``` Reactions are currently unavailable ·
Author tomasmatulis0
GitHub
github.com › HugoCapocci › react-download-button
GitHub - HugoCapocci/react-download-button: A button to allow download file when clicked, whatever the action, even after HTTP POST · GitHub
import DownloadButton from 'react-dfb'; // you can also import flow type if needed import type { DownloadData } from 'react-dfb'; Two required props: onClick: Function to call on button click · downloadData: Object having html5 file informations ...
Author HugoCapocci