Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Failed to load PDF document" HTML5 Object

Tags:

html

pdf

I am trying to display some PDF documents on my webpage, but I keep getting Failed to load PDF document in my browser. I have tried it in both Google Chrome and Mozilla Firefox (both latest versions). Whenever I inspect the object, and I open the src url directly in my browser, the path is correct and it downloads the PDF file.

Here's the code I'm using:

<object data="https://example.com/_f/user/pdf/my_file.pdf" type="application/pdf" width="100%" height="100%">
  <p>Alternative text</p>
</object>

Update

I have found an solution here on StackOverflow that I have used. Works great!

like image 451
Arko Elsenaar Avatar asked Apr 29 '15 23:04

Arko Elsenaar


People also ask

How do I fix failed to load PDF?

Change PDF settings in Chrome Scroll to the bottom and click Advanced. In the Privacy section click Content settings. Now select PDF documents from the list. Now enable Download PDF files instead of automatically opening them in Chrome option.

How do I open a PDF in HTML5?

To embed a PDF file in an HTML5 page, use the <iframe> element.

Why is it showing failed to load PDF document?

The “Failed to Load PDF Document” error message indicates that the web browser you are using, Google Chrome, is trying to open the electronic transcript within its own native PDF viewer. Because the transcript is a secured PDF, it must be opened with Adobe Acrobat Reader.

How do you upload a PDF in HTML?

Using an iframe tag is the second way to embed a pdf file in an HTML web page. In web development, web developers use the iframe tag to embed files in various formats and even other websites within a web page. Due to its wide compatibility, the iframe tag is widely used for embedding pdf.


1 Answers

I had the same problem and had to change theContent-Disposition attachment header.

I changed:

Content-Disposition: attachment; filename="filename.pdf"

TO

Content-Disposition: inline; filename="filename.pdf"

See also: How to force files to open in browser instead of download (pdf)?

like image 59
Nactive Avatar answered Oct 07 '22 13:10

Nactive