php 在不使用内置 PDF 查看器的情况下将 PDF 嵌入网页

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

Embed the PDF in a webpage without using the built-in PDF viewer

phpjavascripthtmlpdfpdf-viewer

提问by user782104

Currently I am using the standard way to embed an pdf to the browser, however, the built-in pdf viewer for my target browser is not working as expected. I would like to force (Chrome, Firefox and IE8 (if possible, but IE9+ is also ok)) to use the adobe reader. The problem is , I can only change this option manually. Is there any way to change the option in HTML/ JS/ PHP ? Thanks.

目前我正在使用标准方式将 pdf 嵌入浏览器,但是,我的目标浏览器的内置 pdf 查看器没有按预期工作。我想强制(Chrome、Firefox 和 IE8(如果可能,但 IE9+ 也可以))使用 adobe 阅读器。问题是,我只能手动更改此选项。有什么方法可以更改 HTML/JS/PHP 中的选项吗?谢谢。

<OBJECT data="YourFile.pdf" TYPE="application/x-pdf" TITLE="SamplePdf" 
WIDTH=200 HEIGHT=100>
    <a href="YourFile.pdf">shree</a> 
</object>

I try to find the solution and someone suggested header, not working unfortunately e.g.

我试图找到解决方案和有人建议的标题,不幸的是,例如

Content-Type: application/pdf
Content-Disposition: inline; filename.pdf

回答by Bradly Spicer

I did this a while ago. Using JQuery was a great way to get round this :)

我前一段时间做了这个。使用 JQuery 是解决这个问题的好方法:)

pdf.js:

pdf.js:

https://github.com/mozilla/pdf.js

https://github.com/mozilla/pdf.js

Hope this helps!

希望这可以帮助!

回答by Suresh Peiris

You can use Google PDF viewer to embed pdf files on to your website. Use this link https://docs.google.com/viewer

您可以使用 Google PDF 查看器将 pdf 文件嵌入您的网站。使用此链接https://docs.google.com/viewer

Example:

例子:

<iframe src="http://docs.google.com/viewer?url={HTTP PATH OF THE PDF FILE}&embedded=true" width="600" height="780" style="border: none;"></iframe>

回答by Roy M J

Check out PDFObjectwhich is a Javascript library to embed PDFs in HTML files. It handles browser compatibility pretty well and will most likely work on IE8.

查看PDFObject,它是一个用于将 PDF 嵌入 HTML 文件的 Javascript 库。它可以很好地处理浏览器兼容性,并且很可能适用于 IE8。

In your HTML, you could set up a div to display the PDFs:

在您的 HTML 中,您可以设置一个 div 来显示 PDF:

<div id="pdfRenderer"></div>

Then, you can have Javascript code to embed a PDF in that div:

然后,您可以使用 Javascript 代码在该 div 中嵌入 PDF:

var pdf = new PDFObject({
  url: "https://sample.pdf",
  id: "pdfRendered",
  pdfOpenParams: {
    view: "FitH"
  }
}).embed("pdfRenderer");

Cheers

干杯

回答by Rohan Kumar

You can use document-vieweror best-pdf-viewer

您可以使用document-viewerbest-pdf-viewer

The above uses javascript, html. Yesif you don't want to convert these in js or htmlthen you can use Swftools. Here you can make your own skin, then read : SWFTools (pdf2swf) to properly work with Flex

以上使用javascript, html. 是的,如果您不想将这些转换为,js or html那么您可以使用Swftools。在这里您可以制作自己的皮肤,然后阅读:SWFTools (pdf2swf) 以正确使用 Flex

Showing pdfin Iframemay be another option.

pdfIframe 中显示可能是另一种选择。

You problem may match with Show pdf file into browser without Adobe Reader

您的问题可能与Show pdf file into browser without Adob​​e Reader匹配

回答by Andrew Bucklin

Trick Chrome and Firefox (and maybe other browsers) into displaying the PDFs using the Adobe Reader plugin (for full PDF Open Parameters support among other benefits) by using one of the following 'Adobe PDF in XML Format' types in your embed code:

通过在嵌入代码中使用以下“XML 格式的 Adob​​e PDF”类型之一,诱使 Chrome 和 Firefox(可能还有其他浏览器)使用 Adob​​e Reader 插件显示 PDF(以获得完整的 PDF 打开参数支持以及其他好处):

application/vnd.adobe.pdfxml
application/vnd.adobe.x-mars

This works fine as of my answer today and I'm hopeful it will continue to work fine. I'm using it currently with standard PDF files as a workaround for embedding PDF files in the browser that need to use the Adobe PDF plugin rather than the browser's built-in PDF rendering. Even though my PDF files are standard (non-XML) files, they appear to load just fine with this new application type parameter.

这在我今天的回答中运行良好,我希望它会继续正常运行。我目前将它与标准 PDF 文件一起使用,作为在需要使用 Adob​​e PDF 插件而不是浏览器的内置 PDF 渲染的浏览器中嵌入 PDF 文件的解决方法。尽管我的 PDF 文件是标准(非 XML)文件,但它们似乎可以通过这个新的应用程序类型参数正常加载。

<OBJECT data="YourFile.pdf" TYPE="application/vnd.adobe.pdfxml" TITLE="SamplePdf" 
WIDTH=200 HEIGHT=100>
    <a href="YourFile.pdf">shree</a> 
</object>