webodf / ViewerJS

ViewerJS: Document Reader in JavaScript
http://viewerjs.org
1.94k stars 421 forks source link

PDF Content Type Incorrectly Strict #259

Open ForsteriteFoe opened 5 years ago

ForsteriteFoe commented 5 years ago

Was trying to use the ViewerJS to point to a PHP script which served the appropriate document, but was having problems getting this to work.

This was a bit difficult to determine, as the documentation may be interpreted to mean that it is the file extension not the MIME type which determines how the ViewerJS determines the file type. Apparently this uses the HTTP "Content-Type" header to identify that it is looking at a PDF document or something else. I had been serving PDF documents using the following HTTP which did not work:

header('Content-Type: application/pdf; charset=utf-8');

Changing this to the following allowed the script to properly detect that it was a PDF: header('Content-Type: application/pdf');

My understanding is that the first is a valid and actually more strict MIME description (see MDN: Content-Type ). My suggestion is that the matching be done through a fuzzy match to work with this.