问题
I have this situation that is little bit hard to explain. I have this url that ends in this format of www..../samplePDF.HTM when I open the url in Internet Explorer, it reads the page as pdf (it doesnt care about the extension of .HTM), however when I open the same url in Chrome it wont render and just show me random symbols, like it cant encrypt it. is there away to have the chrome render the content and recognize the url as a PDF file. I cant change the url to samplePDF.PDF ... but if I save it locally and rename the url to "samplePDF.PDF" I can open it as pdf on my computer. I just need to be able to open it on the chrome. Thanks for the help in advance.
回答1:
Dude first of all, this question shouldn't posted here. StackOverflow is for programming issues, it should be posted on SuperUser.
Second,from what I understood from your question, this depends on how each browser render the file. I think an extension for chrome could solve the problem. Try to install this extension
回答2:
How about trying to change the ending code to HTML see if that works? Plus what you have to realize each browser has a different way of going at these sites than others... So yes some sites work on Chrome and not on internet explorer and vise versa... But as long as you can get it to work on IE and on you computer, why do you need it on your computer... And hey, may I recommend you try and make this relevant to the page? this should be in SuperUser not here
回答3:
You could embed the PDF into an HTML document and make it fill the whole page. (Check this answer: Recommended way to embed PDF in HTML?)
回答4:
Browsers parse the files according to the MimeType the server returned (in the HTTP respnse headers), not according to the file extension, when you mentioned that it's working on IE I was surprised, so I tested it and you were right, it's like IE tries to parse the downloaded data itself if it failed to continue parsing according to the MimeType, so you can count IE an exception, most browsers don't do that.
As for you, i assume that this is a script file that's generating a pdf, in which case you have to supply the MimeType in the script itself, for example in php you can put the following line at the start of the script:
header("Content-Type: application/pdf");
or you have an existing file on the server, in which case the web-server (Apache or IIS) is trying to automatically assign mime type to the file, you have to override this.
In Apache for example you can make a .htaccess
file in the same folder and put something like this in it:
<Files samplePdf.htm>
AddType application/pdf .htm
</Files>
来源:https://stackoverflow.com/questions/22976041/chrome-not-rendering-pdf-file-without-extension