Javascript 如何嵌入适用于所有 Web 和移动浏览器的 PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6137457/
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
How to embed PDFs that work in all web and mobile browsers
提问by Silas Paul
My client asked me to create a page which contains PDF. I used Embed, Iframe tags, it worked in Mozilla but did not work in IE and Mobile browser.
我的客户要求我创建一个包含 PDF 的页面。我使用了 Embed、Iframe 标签,它在 Mozilla 中有效,但在 IE 和移动浏览器中无效。
I know that all browsers will read .pdf directly but I want it to be embed.
我知道所有浏览器都会直接读取 .pdf 但我希望它被嵌入。
Is there any way?
有什么办法吗?
Please help me..
请帮我..
回答by BZ1
If you give a link to the PDF on the web page, any browser will be able to download the file and then the user can open it in a PDF viewer of his choice.
如果您在网页上提供指向 PDF 的链接,则任何浏览器都可以下载该文件,然后用户可以在他选择的 PDF 查看器中打开它。
If you want to embed the PDF document in a web page, then the browser needs to have a PDF plugin installed. This may not be the case with all browsers. The PDF will be displayed only if the PDF viewer application's plugin is registered with the browser.
如果要将 PDF 文档嵌入网页中,则浏览器需要安装 PDF 插件。这可能不是所有浏览器的情况。只有在浏览器中注册了 PDF 查看器应用程序的插件时,才会显示 PDF。
The other way of embedding the PDF document is to use a server-side component that renders the PDF as ordinary HTML web page elements. Google has an embeddable PDF viewer.
嵌入 PDF 文档的另一种方法是使用服务器端组件,将 PDF 呈现为普通的 HTML 网页元素。Google 有一个可嵌入的 PDF 查看器。
Google Docs offers an undocumented feature that lets you embed PDF files and PowerPoint presentations in a web page. The files don't have to be uploaded to Google Docs, but they need to be available online.
Google Docs 提供了一项未公开的功能,可让您在网页中嵌入 PDF 文件和 PowerPoint 演示文稿。这些文件不必上传到 Google Docs,但需要在线可用。
回答by Simon Bengtsson
You can also use Mozilla's pdf rendererwritten in javascript. It is rather complex getting started, but all options are there. It is the pdf reader available in Firefox and extensions exist for other browsers. Fun fact: It is by far the most starred library on github when searching for pdf.
您还可以使用用 javascript 编写的Mozilla pdf 渲染器。入门相当复杂,但所有选项都在那里。它是 Firefox 中可用的 pdf 阅读器,并且存在适用于其他浏览器的扩展。有趣的事实:到目前为止,它是 github 上搜索 pdf 时加星最多的库。