in the java class
public StreamedContent getPdfFile() throws Exception {
FacesContext facesContext = FacesContext.getCurrentInstance();
PortletResponse portletResponse= (PortletResponse)facesContext.getExternalContext().getResponse();
ResourceResponse portletResourceResponse = (ResourceResponse) portletResponse;
portletResourceResponse.setContentType("application/pdf");
/*the following line is very important */
portletResourceResponse.flushBuffer();
OutputStream out = portletResourceResponse.getPortletOutputStream();
out.write(PdfGenerator.pdfFromHtmlContent(content);
out.flush();
facesContext.responseComplete();
return null
}
---------------------------------------------------------------------------------------------------------
in the xhtml page
<p:commandButton value="download PDF" ajax="false">
<p:fileDownload value="#{ph.pdfFile}" />
</p:commandButton>
public StreamedContent getPdfFile() throws Exception {
FacesContext facesContext = FacesContext.getCurrentInstance();
PortletResponse portletResponse= (PortletResponse)facesContext.getExternalContext().getResponse();
ResourceResponse portletResourceResponse = (ResourceResponse) portletResponse;
portletResourceResponse.setContentType("application/pdf");
/*the following line is very important */
portletResourceResponse.flushBuffer();
OutputStream out = portletResourceResponse.getPortletOutputStream();
out.write(PdfGenerator.pdfFromHtmlContent(content);
out.flush();
facesContext.responseComplete();
return null
}
---------------------------------------------------------------------------------------------------------
in the xhtml page
<p:commandButton value="download PDF" ajax="false">
<p:fileDownload value="#{ph.pdfFile}" />
</p:commandButton>
Comments
Post a Comment