在 HTML 中嵌入 PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10215470/
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
Embed PDF in HTML
提问by gene b.
I need to embed a PDF document inside an HTML page. The PDF is dynamically generated, i.e., not a static file, but rather a byte-array generated using a PDF toolkit (in my case, "Apache PDFBox"). I have a Java Web app.
我需要在 HTML 页面中嵌入一个 PDF 文档。PDF 是动态生成的,即不是静态文件,而是使用 PDF 工具包(在我的情况下为“Apache PDFBox”)生成的字节数组。我有一个 Java Web 应用程序。
From what I understand, there are 2 ways to embed a PDF: using the OBJECT and IFRAME tags.
据我了解,有两种方法可以嵌入 PDF:使用 OBJECT 和 IFRAME 标签。
The
<object>
tag does not work for me. When I have a dynamically-generated source, it takes 20 sec. to render. I'm not sure if that is a problem of the Acrobat Reader plugin, but I have not been able to get around this strange behavior.The
<iframe>
tag works fine and displays the PDF. But here's the problem: My PDF has a Submit button which submits the form. After I submit the form, I need to re-display the PDF with some kind of status message. The form output goes to the sameframe. Thus, I get a Frame-inside-a-Frame. There is no way to break out of the current frame, because I don't have access to the<form>
tag. The form is contained inside the PDF and Acrobat takes care of submitting the form. If I have extra elements in my frame, such as a text message, I will get cascading frames.
该
<object>
标签对我不起作用。当我有一个动态生成的源时,它需要 20 秒。渲染。我不确定这是否是 Acrobat Reader 插件的问题,但我无法解决这种奇怪的行为。该
<iframe>
标签工作正常并显示 PDF。但问题是:我的 PDF 有一个提交按钮,用于提交表单。提交表单后,我需要重新显示带有某种状态消息的 PDF。表单输出到同一帧。因此,我得到了一个 Frame-inside-a-Frame。没有办法跳出当前帧,因为我无权访问<form>
标签。表单包含在 PDF 中,Acrobat 负责提交表单。如果我的框架中有额外的元素,例如文本消息,我将获得级联框架。
Any ideas how to resolve this?
任何想法如何解决这个问题?
回答by idleMind
<object data="myfile.pdf" type="application/pdf" width="100%" height="100%">
<p>It appears you don't have a PDF plugin for this browser.
No biggie... you can <a href="myfile.pdf">click here to
download the PDF file.</a></p>
</object>
for more details and examples.. visit this URL: http://pdfobject.com/markup/index.php
有关更多详细信息和示例.. 访问此 URL:http: //pdfobject.com/markup/index.php