【问题标题】:<p:media display pdf from folder dynamically<p:media 动态显示文件夹中的 pdf
【发布时间】:2014-07-09 20:40:22
【问题描述】:

我有几个保存在...WebContent/Manuals/filename.pdf 中的pdf 文件,我正试图在我的页面上显示这些文件。我在 Chrome 中收到“加载 PDF 文档失败”消息。

我的 Jsf:

&lt;p:media value="#{reviewBean.manual}" player="pdf" height="600px" width="1000px" /&gt;

我的@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>?

就我而言,我不需要使用 &lt;f:param 检索值

我的文件路径是否不正确,无法显示图像?还是我错误地构建了流?非常感谢任何指导。

【问题讨论】:

    标签: pdf jsf-2 primefaces media


    【解决方案1】:

    我仅通过将 url 返回为 String 来解决此问题。

    public String getManual() {     
        return user.getManuals().get(user.getLData().getDepart());              
    }
    

    其中返回值为pdf的文件路径:Manuals/filename.pdf

    【讨论】:

      猜你喜欢
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-10
      • 1970-01-01
      • 1970-01-01
      • 2013-01-07
      相关资源
      最近更新 更多