Next.js Discord

Discord Forum

How to open a local PDF file in a tab?

Answered
English Lop posted this in #help-forum
Open in Discord
English LopOP
I have a PDF file in my public folder but I can't seem to load it

I've tried

<embed 
    src="/public/MyPDF.pdf" 
    type="application/pdf" 
    style={{width: '100%', height: '100vh'}}
  />


I've also tried
<iframe src="/public/MyPDF.pdf"
    style={{width: '100%', height: '100vh'}} 
    />

But I get 404s with both. I've also tried with and without 'use client'

Ideally I want to open just the pdf using the browser's own PDF viewer.
Answered by Ray
oh should be this
<object data="/MyPDF.pdf" type="application/pdf" width="100%" height="500px" />
View full answer

6 Replies

@Ray try ts <object data="/public/MyPDF.pdf" type="application/pdf" width="100%" height="500px" />
English LopOP
I get a blank white page, and this is in the dev tools
@English Lop I get a blank white page, and this is in the dev tools
oh should be this
<object data="/MyPDF.pdf" type="application/pdf" width="100%" height="500px" />
Answer
English LopOP
had to change the height to screen but it works perfectly
thank you
@English Lop thank you
np please mark solution