How to use PDFObject.js with all browser

3.4k Views Asked by At

I want to insert in my web application a ViewerPDF. So for this I have download PDFObject. Now I have in my page this code:

<script src="Scripts/PDF/pdfobject.js" type="text/javascript"></script>
 <script>
   var url ="urlPDF";
   var container = document.getElementById("divID");
   var options = {
        fallbackLink: "<p>This is a <a href='[url]'>fallback link</a></p>",
        height: "500px",
        width: "500px",
        pdfOpenParams: {
            view: 'FitV',
            pagemode: 'thumbs',
            search: 'lorem ipsum'
        }
    };
  PDFObject.embed(url, container, options);
</script>

With this code, if I try to open my samplePage.html with Internet Explorer I can see the PDF. If I try to open samplePage.html with Mozilla Firefox I can see this: enter image description here

If I try to open samplePage.html with Google Chrome I can't see never.

1

There are 1 best solutions below

1
On

If Mozilla is displaying the PDF's source code (as shown in your screenshot), and Chrome doesn't recognize the file (won't open it), you may not have the correct MIME type set on the server. Ensure the file is being served as application/PDF.

(Note that PDFObject 2.0 is not working in the latest versions of Firefox due to Mozilla removing the navigator MIME types array.)