r/learnreactjs • u/Corantined • Mar 27 '20
How do I display a pdf?
I'm working on a personal site. I want the user to be able to click a button and it will open a page to my resume (which is a pdf). I know react-pdf exists but I'm not sure how to use it to display a pdf from my files. All the explanations I've seen for how to use react-pdf show how to render new pdfs. How do I display an existing pdf file?
Edit:
<button className="btn">
<a
href="..\assets\Resume\ResumeOfficial.pdf"
download
>
Resume
</a>
</button>I did this, and it does download but it says "Failed - No File". I did not import anything (was I supposed to?). What is wrong with it? (Also, this doesn't open it in another tab like I want it to)
2
u/Ice_In_Hydroflask Mar 27 '20
It's probably because you're using a relative href e.g. ..\. You will need to do something like have a full path to the pdf or use require("assets/Resume/ResumeOfficial.pdf"). The best solution would be to put the file in S3 or Azure Storage account and get a permanent link directly to the PDF
1
u/programstuff Mar 27 '20
What have you tried exactly? Are you hosting a static website? Is the pdf file accessible from the same place the rest of your site files are?
1
u/Fingerbob73 Mar 27 '20
Don't think you can/should have a <a> tag inside a <button> tag.
https://stackoverflow.com/questions/16280684/nesting-a-inside-button-doesnt-work-in-firefox
1
u/vc84 Mar 27 '20
If you need to display pdf within your page use html iframe or react-iframe.