将原始字节作为 PDF 嵌入 JSP 中
我有一个包含根据用户请求生成的 PDF 原始字节的 bean。我想向用户显示此 PDF,而不真正将 PDF 文件保留在我的服务器上。
在我的 jsp 中,我尝试过类似的标签,
<object data="#{bean.pdfBytes}" type="application/pdf" ></object>
<object type="application/pdf" width="600" height="400">
<h:outputFormat value="#{bean.pdfBytes}" escape="false"/>
</object>
但这非常失败。任何帮助将不胜感激。提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其写入响应的输出流。假设您使用 iText 生成 PDF,将响应的输出流传递给
PdfWrter#getInstance()
。然而,这将在浏览器中显示完整的 PDF。如果您想要“另存为”对话框,只需将标题中的“内联”部分更改为“附件”即可。或者,如果您确实希望将其嵌入
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
inline
part 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 aboveresponse
job inside thedoGet()
method and finally let<object>
's URL point to that servlet.