Javascript 如何在 HTML 页面中嵌入文档?

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

How to embed a document in HTML page?

javascripthtmlservletsbrowser-plugin

提问by user339108

We would like to show the document (e.g. pptx, xlsx, docx, pdf, html) in a html page after retrieving it from the database via a servlet's doGet method.
Can anyone share some snippets on how to achieve this?

我们希望通过 servlet 的 doGet 方法从数据库中检索文档(例如pptx, xlsx, docx, pdf, html)后,在 html 页面中显示该文档。
任何人都可以分享一些关于如何实现这一目标的片段吗?

回答by mplungjan

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>
  2. object/embed: <object src="somepage.pdf"><embed src="somepage.pdf"></embed></object>
  1. 框架<iframe src="somepage.pdf"></iframe>
  2. 对象/嵌入<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

这是一个stackoverflow搜索

回答by marlonpd

Google docs viewer can handle this.

谷歌文档查看器可以处理这个。

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>

回答by Ajay Narang

If you are looking for a pure HTML version of the document (for fast rendering and cross browser support), you can go through Docspad. Docspad helps embedding all the different popular document formats into your web application. http://docspad.com

如果您正在寻找文档的纯 HTML 版本(用于快速渲染和跨浏览器支持),您可以通过 Docspad。Docspad 有助于将所有不同的流行文档格式嵌入到您的 Web 应用程序中。http://docspad.com