Embed PDF in HTML

gene b. picture gene b. · Apr 18, 2012 · Viewed 30.3k times · Source

I need to embed a PDF document inside an HTML page. The PDF is dynamically generated, i.e., not a static file, but rather a byte-array generated using a PDF toolkit (in my case, "Apache PDFBox"). I have a Java Web app.

From what I understand, there are 2 ways to embed a PDF: using the OBJECT and IFRAME tags.

  • The <object> tag does not work for me. When I have a dynamically-generated source, it takes 20 sec. to render. I'm not sure if that is a problem of the Acrobat Reader plugin, but I have not been able to get around this strange behavior.

  • The <iframe> tag works fine and displays the PDF. But here's the problem: My PDF has a Submit button which submits the form. After I submit the form, I need to re-display the PDF with some kind of status message. The form output goes to the same frame. Thus, I get a Frame-inside-a-Frame. There is no way to break out of the current frame, because I don't have access to the <form> tag. The form is contained inside the PDF and Acrobat takes care of submitting the form. If I have extra elements in my frame, such as a text message, I will get cascading frames.

Any ideas how to resolve this?

Answer

idleMind picture idleMind · Aug 6, 2012
<object data="myfile.pdf" type="application/pdf" width="100%" height="100%">

  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>

</object>

for more details and examples.. visit this URL: http://pdfobject.com/markup/index.php