简体   繁体   English

如何在 HTML 页面中嵌入 PDF?

[英]How to embed a PDF in HTML page?

We would like to show the PDF document in an HTML page after retrieving it from the database via a servlet's doGet method.我们希望在通过 servlet 的doGet方法从数据库中检索 PDF 文档后,在 HTML 页面中显示它。

Can anyone share some snippets on how to achieve this?谁能分享一些关于如何实现这一目标的片段?

Non-html content apart from images needs to be retrieved using an object, embed or iframe tag需要使用对象、嵌入或 iframe 标签检索除图像之外的非 html 内容

  1. iframe : <iframe src="somepage.pdf"></iframe> iframe : <iframe src="somepage.pdf"></iframe>
  2. object/embed : <object src="somepage.pdf"><embed src="somepage.pdf"></embed></object>对象/嵌入<object src="somepage.pdf"><embed src="somepage.pdf"></embed></object>

somepage.pdf could be somepage.jsp?filename=somepage&mimetype=application/pdf somepage.pdf 可能是 somepage.jsp?filename=somepage&mimetype=application/pdf

Here is an interesting link How to Embed Microsoft Office or PDF Documents in Web Pages这是一个有趣的链接如何在网页中嵌入 Microsoft Office 或 PDF 文档

and here is a stackoverflow search这是一个计算器搜索

Google docs viewer can handle this. Google 文档查看器可以处理这个问题。

try尝试

<html>
    <head>
        <style>
            *{margin:0;padding:0}
            html, body {height:100%;width:100%;overflow:hidden}
        </style>
        <meta charset="utf-8">
            <?php
                 $url = $_GET['url'];
             ?>
        <title><?php echo $url; ?></title>
    </head>
    <body>
        <iframe src="http://docs.google.com/viewer?url=<?=urlencode($url)?>&embedded=true"  style="position: absolute;width:100%; height: 100%;border: none;"></iframe>
    </body>
</html>

If you are looking for a pure HTML version of the document (for fast rendering and cross browser support), you can go through Docspad.如果您正在寻找文档的纯 HTML 版本(为了快速呈现和跨浏览器支持),您可以通过 Docspad。 Docspad helps embedding all the different popular document formats into your web application. Docspad 有助于将所有不同的流行文档格式嵌入到您的 Web 应用程序中。 http://docspad.com http://docspad.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM