问题
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
- iframe:
<iframe src="somepage.pdf"></iframe>
- 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