Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to load PDF document in Chrome

I have a PDF file stored on my server. I am unable to access the file using Google Chrome (or Ubuntu Chromium) via URL "sitename/pdfName.pdf"; while I am able to access the same PDF in Internet Explorer or FireFox without a problem.

Chrome is giving this error: "Failed to load PDF document"

Find attaching the error in this link Error Image.

like image 668
Sumit Dobhal Avatar asked Jan 30 '26 12:01

Sumit Dobhal


2 Answers

We had object:none in our security policy inside web.config, that was causing chrome to refuse to open it, and pressing f12 in chrome and then click "console" shows the error message.

Changing web.config security policy to object:self fixed the problem

In our case we could open PDFs in firefox and IE but not in Chrome, so Chrome has a stricter implementation of the security policies.

The below is a suggested edit which I have not tested:

You may also find that Chrome has a problem with the header of the name: Content-Type value: charset=utf-8. Removing it may fix it.

Also, as you are testing this, make sure that cache is not interfering with the response by keep on changing the request URL to something new sitename/pdfName.pdf?val=1 and then with the next test, ?val=2 and so on...

like image 180
user2728841 Avatar answered Feb 01 '26 10:02

user2728841


When we encountered this problem, the only difference between PDF files that did and did not work was in the fist line of the PDF document itself. Here's the difference between the old PDF that caused the error and the fixed version as seen in a binary-enabled text-editor (in this case vim -b):

Original PDF file:

%PDF-1.6^M%<e2><e3><cf><d3>^M

Fixed PDF file:

%PDF-1.6^M
%<e2><e3><cf><d3>^M

So the problem was solved at the source, no need to burden the victims with installing extra software or reinstalling chrome.

I don't know if this is a problem with the PDF generator, or with the chrome plugin. According to the PDF specification the first line of a PDF document has to contain the PDF version, but it's not completely clear to me if the ^M is a valid line separator.

like image 27
Peter Arien Avatar answered Feb 01 '26 08:02

Peter Arien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!