缩放以适合:嵌入在 HTML 中的 PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20562543/
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
Zoom to fit: PDF Embedded in HTML
提问by user3024833
I am embedding a local pdf file into a simple webpage and I am looking to set the initial zoom to fit to the object size. Here is what I tried but it is not affecting the zoom.
我正在将本地 pdf 文件嵌入到一个简单的网页中,并且希望设置初始缩放以适合对象大小。这是我尝试过的,但它不影响缩放。
<embed src="filename.pdf?zoom=50" width="575" height="500">
does anyone know how to modify the code so its initial zoom is set to fit the object size.
有谁知道如何修改代码,以便将其初始缩放设置为适合对象大小。
回答by Rich
Bit of a late response but I noticed that this information can be hard to find and haven't found the answer on SO, so here it is.
回复有点晚,但我注意到这些信息很难找到,而且还没有在 SO 上找到答案,所以就在这里。
Try a differnt parameter #view=FitH to force it to fit in the horzontal space and also you need to start the querystring off with a # rather than an & making it:
尝试不同的参数 #view=FitH 以强制它适合水平空间,并且您还需要使用 # 而不是 & 开始查询字符串:
filename.pdf#view=FitH
What I've noticed it is that this will work if adobe reader is embedded in the browser but chrome will use it's own version of the reader and won't respond in the same way. In my own case, the chrome browser zoomed to fit width by default, so no problem , but Internet Explorer needed the above parameters to ensure the link always opened the pdf page with the correct view setting.
我注意到的是,如果 adobe 阅读器嵌入在浏览器中,这将起作用,但 chrome 将使用它自己的阅读器版本,并且不会以相同的方式响应。在我自己的情况下,chrome 浏览器默认缩放以适应宽度,所以没问题,但 Internet Explorer 需要上述参数以确保链接始终以正确的视图设置打开 pdf 页面。
For a full list of available parameters see this doc
有关可用参数的完整列表,请参阅此文档
EDIT:(lazy mode on)
编辑:(懒惰模式打开)
回答by nazbouy
For me this worked(I wanted to zoom in since the container of my pdf was small):
对我来说这是有效的(我想放大,因为我的 pdf 的容器很小):
<embed src="filename.pdf#page=1&zoom=300" width="575" height="500">
回答by SR Harvey
This method uses "object", it also has "embed". Either method works:
这种方法使用“对象”,它也有“嵌入”。任何一种方法都有效:
<div id="pdf">
<object id="pdf_content" width="100%" height="1500px" type="application/pdf" trusted="yes" application="yes" title="Assembly" data="Assembly.pdf?#zoom=100&scrollbar=1&toolbar=1&navpanes=1">
<!-- <embed src="Assembly.pdf" width="100%" height="100%" type="application/x-pdf" trusted="yes" application="yes" title="Assembly">
</embed> -->
<p>System Error - This PDF cannot be displayed, please contact IT.</p>
</object>
</div>
回答by raf
Bit late response to this question, however I do have something to add that might be useful for others.
对这个问题的回答有点晚,但是我确实要添加一些可能对其他人有用的内容。
If you make use of an iFrame and set the pdf file path to the src, it will load zoomed out to 100%, which the equivalence of FitH
如果您使用 iFrame 并将 pdf 文件路径设置为 src,它将加载缩小到 100%,这与 FitH 等效
回答by anilglpl
Use iframe tag do display pdf file with zoom fit
使用 iframe 标签显示带有缩放比例的 pdf 文件
<iframe src="filename.pdf" width="" height="" border="0"></iframe>
回答by kuz1toro
just in case someone need it, in firefox for me it work like this
以防万一有人需要它,在 Firefox 中对我来说它是这样工作的
<iframe src="filename.pdf#zoom=FitH" style="position:absolute;right:0; top:0; bottom:0; width:100%;"></iframe>