I have a bean with the raw bytes of a PDF that is generated at the user’s request. I want to display this PDF to the user without really persisting the PDF file on my server.
In my jsp I have tried tags like
<object data="#{bean.pdfBytes}" type="application/pdf" ></object>
<object type="application/pdf" width="600" height="400">
<h:outputFormat value="#{bean.pdfBytes}" escape="false"/>
</object>
but this fails terribly. Any help would be appreciated. Thanks in advance.
Write it to the output stream of the response. Let’s assume that you’re using iText to generate the PDF, pass the response’s output stream to
PdfWrter#getInstance().This will however display the PDF in its entirety in the browser. If you want a Save As dialogue, just change the
inlinepart in the header toattachment. Or if you really want to have it embedded in an<object>, then you’d need to create a servlet and do the aboveresponsejob inside thedoGet()method and finally let<object>‘s URL point to that servlet.