2013-04-30 3 views
0

pdf를 생성 한 다음 "SHOW PDF"버튼을 클릭해야하는 요구 사항이 있으므로 다른 창에 표시해야합니다. IText를 사용하여 pdf를 생성하고 내 컴퓨터에 저장할 수있었습니다. java.io.File 객체를 화면에 표시해야하는 백엔드 라이브러리에서 반환 값으로 가져옵니다. 누군가 이걸 어떻게 할 수 있는지 안내해 주실 수 있습니까?Primefaces는 pdf를 생성하고 버튼 클릭시 표시합니다.

내 XHTML 파일에 다음과 같은 코드가 있습니다

<h:commandLink action="PdfDisplayRedirect.xhtml" target="_blank">show PDF</h:commandLink> 

내 PdfDisplayRedirect.xhtml 다음 코드를 가진다 :

<p:media value="#{pdfGenerationAction.fileName}" width="100%" height="300px"> 
Your browser can't display pdf, <h:outputLink value="InitialExamination33.pdf">click</h:outputLink> to download pdf instead. 

내 백업 빈은 다음과 같은 코드가 있습니다

private File initialExaminationFile; 
private generateFile(){ 
    this.initialExaminationFile = backendService.generateFile(); 
} 

클릭하면 새 창이 열립니다. pdf 파일이 표시되지 않습니다. 대신 명령을 호출 한 곳의 화면이 표시됩니다.

도움이 될 것입니다. 감사합니다.

+0

primefaces의 버전을 사용하고 있습니까? – rags

+0

사용중인 브라우저는 무엇입니까? – rags

+0

응답 넝마 주셔서 감사합니다. 나는 primefaces 3.4.2와 파이어 폭스를 브라우저로 사용하고있다. –

답변

2

응답 해 주셔서 감사합니다. 응답이 없습니다. 솔루션을 찾는 사람들이 사용할 수 있도록 게시하고 싶은 솔루션을 직접 찾았습니다.

내 XHTML 파일은 CommandLink는

을 포함
<p:commandLink actionListener="#{pdfGenerationAction.generatePDF(initialExaminationEMRAction.patientID)}" oncomplete="window.open('PdfDisplayRedirect.xhtml')">broadcast Msg</p:commandLink> 

내 pdfGenerationAction 콩 파일 코드의 다음 줄을했다 :

FileInputStream fis = new FileInputStream(this.initialExaminationFile); 
    //System.out.println(file.exists() + "!!"); 
    //InputStream in = resource.openStream(); 
    ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
    byte[] buf = new byte[1024]; 
    try { 
     for (int readNum; (readNum = fis.read(buf)) != -1;) { 
      bos.write(buf, 0, readNum); //no doubt here is 0 
      //Writes len bytes from the specified byte array starting at offset off to this byte array output stream. 
      System.out.println("read " + readNum + " bytes,"); 
     } 
     this.reportBytes = buf; 
    } 

내가 bytearraystream에 내 파일을 변환 내 세션에서 그것을 가능하게합니다. 그런 다음 BalusC의 제안에 따라 Unable to show PDF in p:media generated from streamed content in Primefaces

관련 문제