How to use PDF open parameter (e.g. fitH) in Chrom

2019-03-06 03:23发布

http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf

There are a set of open parameter specify how the viewer should open the pdf . However, with the Chrome and firefox browser's default viewer , it does not work

<object id = 'zoomPage' type='application/pdf' data= '1.pdf#view=fit'><p>The PDF can not display</p></object>

I have tried the fit which I would like the pdf fill the object. If there is no parameter support , are there any workaround ? I tried a lot of approach but none of them work. For example, I also tried using iframe instead of object. However, the content does not resize. Thanks

<iframe src="1.pdf" width=1300 height=3300></iframe>

1条回答
Root(大扎)
2楼-- · 2019-03-06 04:05

Searching a solution for a problem very similar to yours, I found an interesting thread on forum.asp.net. http://forums.asp.net/t/1877403.aspx?Issue+with+embedded+pdf+object+in+chrome+browsers

At the end of the page, there is a workaround by a user working smoothly in Chrome. That seems to solve the problem.

Here it is an example:

<iframe src="/Downloads/MyPdfDocument.pdf#view=fitH" width="700"  height="880"></iframe>

For users fighting with http://pdfobject.com/ -> "pdfobject.js" like me, you can change few lines of code on both minified and develop version of pdfobject.

Find:

c.innerHTML='<object    data="'+a+'" type="application/pdf" width="'+i+'" height="'+z+'"></object>';return c.getElementsByTagName("object")[0];

and change with this line of code:

c.innerHTML='<iframe src="'+a+'" width="'+i+'" height="'+z+'"></iframe>';return c.getElementsByTagName("iframe")[0];

Hope this helps.

查看更多
登录 后发表回答