We would like to show the PDF document in an HTML page after retrieving it from the database via a servlet's doGet
method.
Can anyone share some snippets on how to achieve this?
Using an iframe tag is the second way to embed a pdf file in an HTML web page. In web development, web developers use the iframe tag to embed files in various formats and even other websites within a web page. Due to its wide compatibility, the iframe tag is widely used for embedding pdf.
Fortunately, Adobe has released Adobe PDF Embed API (PDF Embed), an easy way for you to incorporate a PDF directly into your website with just an easy snippet of code.
To attach a file, go to Insert > Attach File in PDF. To embed a file, go to Insert > Embed File in PDF. Browse to and select the file that you want to insert, and click Select on the Select File dialog.
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>
Non-html content apart from images needs to be retrieved using an object, embed or iframe tag
<iframe src="somepage.pdf"></iframe>
<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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With