Html HTML5 中 PDF 对象的初始缩放参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11938141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Initial Zoom Parameter for PDF Object in HTML5
提问by Patrick
I am building a page that will display a PDF file on the page. When viewing this page in Chrome, the zoom level is set by default so that the document is wider and taller than the allotted space. Safari seems to have a preferable default of fitting the page to the available space, just FYI.
我正在构建一个页面,将在页面上显示一个 PDF 文件。在 Chrome 中查看此页面时,默认设置缩放级别,以便文档比分配的空间更宽和更高。Safari 似乎有一个更可取的默认设置,使页面适合可用空间,仅供参考。
I would like to know if there are any parameters that can be set in <object>
to force the initial zoom level of the document. It might be name=initZoom with values like "fitToPage" or "fitToWidth" or "70" (for 70% zoom). It might look something like this:
我想知道是否可以设置任何参数<object>
来强制文档的初始缩放级别。它可能是 name=initZoom,其值为“fitToPage”或“fitToWidth”或“70”(用于 70% 缩放)。它可能看起来像这样:
<object data="/path/to/file.pdf" type="application/pdf">
<param name="initZoom" value="fitToPage" />
</object>
回答by Kurt Pfeifle
Does Adobe's document 'Parameters for opening PDF files'help you?
Adobe 的文档“打开 PDF 文件的参数”对您有帮助吗?
According to that document, something like
根据该文件,类似
<object data="/path/to/file.pdf" type="application/pdf">
<param name="view" value="Fit" />
</object>
could work, or even
可以工作,甚至
<object
data="/path/to/file.pdf#toolbar=1&navpanes=0&scrollbar=1&page=3&view=FitV"
type="application/pdf">
<p>It appears you don't have a PDF plugin for this browser.
No problem though...
You can <a href="/path/to/file.pdf">click here to download the PDF</a>.
</p>
</object>
回答by Kurt Pfeifle
See demo here http://jsfiddle.net/6TNrw/68/
在此处查看演示http://jsfiddle.net/6TNrw/68/
The above works if the pdf viewer object is adobe.
如果 pdf 查看器对象是 adobe,则上述方法有效。
Google chrome has its own pdf viewer so changing its zoom parameter wont work for that.
Google chrome 有自己的 pdf 查看器,因此更改其缩放参数将不起作用。
<object data="http://www.nclabor.com/wh/faqs.pdf?#view=fitH"
type="application/pdf"
width="100%" height="100%">
<param name="view" value="fitH" />
</object>
回答by Johannes
Adding a late answer since none of the existing ones worked for me, and someone might need it.
添加一个迟到的答案,因为现有的答案都不适合我,有人可能需要它。
Instead of adding '#view=fitH' or '#view=fitV' to the pdf url, which didn't work for me, i got it working by adding '#zoom=scale', like this:
我没有在 pdf url 中添加“#view=fitH”或“#view=fitV”,这对我不起作用,而是通过添加“#zoom=scale”来实现,如下所示:
<object data="/path/to/file.pdf#zoom=scale" type="application/pdf">
</object>
Hope this helps someone, and sorry for any inconvenience.
希望这对某人有所帮助,对于任何不便,我们深表歉意。
EDIT: Found more parameters here. Found the link in this thread, which is basically the same question as this.
回答by targetcreature
Another late answer (looks like we're on a 2-year cycle...)
另一个迟到的答案(看起来我们处于 2 年的周期......)
I found that setting the parameter #zoom=Fit
finally did the trick. This is only in FF so far. Chrome is laughing at every parameter I feed it.
我发现设置参数#zoom=Fit
终于成功了。到目前为止,这仅在 FF 中。Chrome 对我提供的每个参数都嗤之以鼻。
Notethat the documentationstates that view
gets the Fit
values, but zoom
is the one that seems to do anything with them.
请注意,文档指出view
获取Fit
值,但zoom
似乎对它们执行任何操作的文档。
I hope this helps someone down the line.
我希望这可以帮助某人下线。