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>
I have found an solution here on StackOverflow that I have used. Works great!
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.
To embed a PDF file in an HTML5 page, use the <iframe> element.
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.
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.
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)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With