【发布时间】:2014-07-09 20:40:22
【问题描述】:
我有几个保存在...WebContent/Manuals/filename.pdf 中的pdf 文件,我正试图在我的页面上显示这些文件。我在 Chrome 中收到“加载 PDF 文档失败”消息。
我的 Jsf:
<p:media value="#{reviewBean.manual}" player="pdf" height="600px" width="1000px" />
我的@SessionScoped Bean:
public StreamedContent getManual() 抛出 IOException {
String type = "application/pdf"; String path = ""; FacesContext context = FacesContext.getCurrentInstance(); if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) { return new DefaultStreamedContent(); } else { path = "C:\\.....\\WebContent\\Manuals\\filename.pdf"; InputStream is = new ByteArrayInputStream(path.getBytes()); return new DefaultStreamedContent(is, type); } }
为了清楚起见,我省略了其他逻辑来决定显示哪个 pdf。
我也试过/Manuals/filename.pdf的文件路径作为路径
我尝试了以下示例:
How to bind dynamic content using <p:media>?
就我而言,我不需要使用 <f:param 检索值
我的文件路径是否不正确,无法显示图像?还是我错误地构建了流?非常感谢任何指导。
【问题讨论】:
标签: pdf jsf-2 primefaces media