How to embed a document in HTML page?

随声附和 提交于 2019-11-26 11:24:00

问题


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?


回答1:


Non-html content apart from images needs to be retrieved using an object, embed or iframe tag

  1. iframe: <iframe src="somepage.pdf"></iframe>
  2. object/embed: <object src="somepage.pdf"><embed src="somepage.pdf"></embed></object>

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

Here is an interesting link How to Embed Microsoft Office or PDF Documents in Web Pages

and here is a stackoverflow search




回答2:


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>



回答3:


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



来源:https://stackoverflow.com/questions/5565759/how-to-embed-a-document-in-html-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!