11

Currently I am using the standard way to embed an pdf to the browser, however, the built-in pdf viewer for my target browser is not working as expected. I would like to force (Chrome, Firefox and IE8 (if possible, but IE9+ is also ok)) to use the adobe reader. The problem is , I can only change this option manually. Is there any way to change the option in HTML/ JS/ PHP ? Thanks.

<OBJECT data="YourFile.pdf" TYPE="application/x-pdf" TITLE="SamplePdf" 
WIDTH=200 HEIGHT=100>
    <a href="YourFile.pdf">shree</a> 
</object>

I try to find the solution and someone suggested header, not working unfortunately e.g.

Content-Type: application/pdf
Content-Disposition: inline; filename.pdf
Oliver Schafeld
  • 17,358
  • 2
  • 15
  • 13
user782104
  • 13,233
  • 55
  • 172
  • 312
  • 1
    the headers approach is correct, you need to slow the full ode you tried –  Aug 23 '13 at 02:35
  • Thanks for reply. It seems the header only can change from viewing pdf using build in viewer to download the pdf. Is it possible to change the viewer as well? – user782104 Aug 23 '13 at 02:49
  • Content-Disposition: Attachment – user782104 Aug 23 '13 at 02:57
  • 2
    you can't change the users browser –  Aug 23 '13 at 03:14
  • 1
    Would an embedded Google Viewer achieve your goal? https://docs.google.com/viewer – sideroxylon Aug 28 '13 at 07:05
  • I think you want application/octet-stream, it will prompt the use to download or open the file, usually in Reader if they have it installed. – j_mcnally Sep 03 '13 at 02:53
  • The suggested header solution worked for me as well. Pay attention that your PDF Plugin is really enabled in the browser. For Firefox: >Tools >Options >Applications :PDF → "Preview in Firefox". – Avatar Apr 15 '14 at 06:15

3 Answers3

10

You can use Google PDF viewer to embed pdf files on to your website. Use this link https://docs.google.com/viewer

Example:

<iframe src="https://docs.google.com/viewer?url={HTTP PATH OF THE PDF FILE}&embedded=true" width="600" height="780" style="border: none;"></iframe>

https://docs.google.com/viewer?url=http://research.google.com/archive/bigtable-osdi06.pdf enter image description here

K J
  • 8,045
  • 3
  • 14
  • 36
Suresh Peiris
  • 396
  • 2
  • 14
4

Check out PDFObject which is a Javascript library to embed PDFs in HTML files. It handles browser compatibility pretty well and will most likely work on IE8.

In your HTML, you could set up a div to display the PDFs:

<div id="pdfRenderer"></div>

Then, you can have Javascript code to embed a PDF in that div:

var pdf = new PDFObject({
  url: "https://sample.pdf",
  id: "pdfRendered",
  pdfOpenParams: {
    view: "FitH"
  }
}).embed("pdfRenderer");

Cheers

Roy M J
  • 6,926
  • 7
  • 51
  • 78
  • 1
    Thanks for your help , it does not work as pdfobject is an plugin that create html tag and inject into div by using javascript. Since chrome pdf viewer don't have view parameter like adboe , it does not work thanks for your help – user782104 Aug 28 '13 at 11:08
0

Trick Chrome and Firefox (and maybe other browsers) into displaying the PDFs using the Adobe Reader plugin (for full PDF Open Parameters support among other benefits) by using one of the following 'Adobe PDF in XML Format' types in your embed code:

application/vnd.adobe.pdfxml
application/vnd.adobe.x-mars

This works fine as of my answer today and I'm hopeful it will continue to work fine. I'm using it currently with standard PDF files as a workaround for embedding PDF files in the browser that need to use the Adobe PDF plugin rather than the browser's built-in PDF rendering. Even though my PDF files are standard (non-XML) files, they appear to load just fine with this new application type parameter.

<OBJECT data="YourFile.pdf" TYPE="application/vnd.adobe.pdfxml" TITLE="SamplePdf" 
WIDTH=200 HEIGHT=100>
    <a href="YourFile.pdf">shree</a> 
</object>
Andrew Bucklin
  • 699
  • 8
  • 19