macos 在 safari 中显示 pdf 文档

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8252751/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:38:26  来源:igfitidea点击:

showing pdf document in safari

javascriptmacospdfsafari

提问by coure2011

I want to show pdf document embedded in html. I am trying code like this but its showing me missing plugin error.

我想显示嵌入在 html 中的 pdf 文档。我正在尝试这样的代码,但它显示我缺少插件错误。

But if I drag the same pdf file to browser it opens it nicely. Why its asking for plugin in html document?

但是如果我将相同的 pdf 文件拖到浏览器,它会很好地打开它。为什么它在 html 文档中要求插件?

<object data="pdfobject.pdf#view=FitV" type="application/pdf" width="100%" height="100%"></object>

回答by Cymbals

Safari just updated their browser which will now properly display pdf's in iframes. Back in the summer of 2011 it did not. Make sure you use an id.

Safari 刚刚更新了他们的浏览器,现在可以在 iframe 中正确显示 pdf。早在 2011 年夏天,它就没有。确保您使用了 id。

 <div id="scroller">
<iframe name="myiframe" id="myiframe" src="viewpdf-safari.php">
</div>

Then in the css add

然后在css中添加

#myiframe {width:600px; height:100%;} 

Here's the problem you'll run into: As of today, the iframe will display the pdf, yes, but navigation thru the pdf is a pain. With touch scrolling, the whole iframe will try to scroll, and not the pdf, forcing you to use two finger scrolling (one finger to hold down the iframe, the other to slow-scroll).

这是您将遇到的问题:截至今天,iframe 将显示 pdf,是的,但是通过 pdf 导航很痛苦。使用触摸滚动时,整个 iframe 将尝试滚动,而不是 pdf,迫使您使用两根手指滚动(一根手指按住 iframe,另一根手指慢速滚动)。

Other browsers filler the whole width on iframe properly, but safari does not right now. I'd suggest having a button or a link to open the pdf directly in a new window for now, so that users won't have two-finger-hell.

其他浏览器可以正确填充 iframe 的整个宽度,但 safari 现在不能。我建议现在有一个按钮或链接可以直接在新窗口中打开 pdf,这样用户就不会有两指地狱。

Another alternative is to try to control the scrolling with the outer div, as mentioned in the link below, but I couldn't get it to work.

另一种选择是尝试使用外部 div 控制滚动,如下面的链接中所述,但我无法让它工作。

how to properly display an iFrame in mobile safari

如何在移动 Safari 中正确显示 iFrame

回答by rob mayoff

Try using an IFRAMEto show the document instead of using an OBJECT.

尝试使用IFRAME来显示文档而不是使用OBJECT

回答by Omtara

Opening a PDF file directly is different than opening an HTML file containing a PDF. Try using an IFRAME as the other post suggests, or use some PDF2SWF viewer listed in the following post:

直接打开 PDF 文件与打开包含 PDF 的 HTML 文件不同。尝试使用其他帖子建议的 IFRAME,或使用以下帖子中列出的一些 PDF2SWF 查看器:

Recommended way to embed PDF in HTML?

在 HTML 中嵌入 PDF 的推荐方法?