问题
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.
回答1:
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...
回答2:
This might be due to Chrome’s built-in PDF Viewer not being able to open Firmex’s protected PDF document.
Try:
- Opening Google Chrome (obviously)
- In the top right, click More Untitled.png, then Settings.
- At the bottom, click Show Advanced Settings.
- Under Privacy, click Content Settings
- Under PDF Documents, check the box next to "Open PDF files in the default PDF viewer application."
- Once you have made the change, PDF files should open in Adobe Reader or Adobe Acrobat, rather than in Google Chrome.
Although it may not be ideal, it's a good alternative for now.
回答3:
You may also find that Chrome has a problem with the header of the name: Content-Type value: charset=utf-8. For IIS you can remove it by placing this web.config file where the PDF is located:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
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...
来源:https://stackoverflow.com/questions/45467019/failed-to-load-pdf-document-in-chrome