<p:outputPanel deferred="true"> <p:tabView> <p:tab title="URL"> <pe:documentViewer height="500" url="/sections/documentviewer/book.pdf"/> </p:tab> <p:tab title="Resource"> <pe:documentViewer height="500" library="books" name="hood.pdf" zoom="page-width"/> </p:tab> <p:tab title="StreamedContent"> <pe:documentViewer height="500" value="#{basicDocumentViewerController.content}" zoom="page-width"/> </p:tab> </p:tabView> </p:outputPanel>
@Named @RequestScoped public class BasicDocumentViewerController implements Serializable { private static final long serialVersionUID = 1L; private String downloadFileName = "pfe-rocks.pdf"; public StreamedContent getContent() { try { return DefaultStreamedContent.builder() .contentType("application/pdf") .name("jack.pdf") .stream(() -> { try { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final Document document = new Document(); PdfWriter.getInstance(document, out); document.open(); for (int i = 0; i < 50; i++) { document.add(new Paragraph("All work and no play makes Jack a dull boy")); } document.close(); return new ByteArrayInputStream(out.toByteArray()); } catch (Exception e) { e.printStackTrace(); return null; } }) .build(); } catch (final Exception e) { e.printStackTrace(); return null; } } public String getDownloadFileName() { return downloadFileName; } public void setDownloadFileName(final String downloadFileName) { this.downloadFileName = downloadFileName; } }