Skip to content

Instantly share code, notes, and snippets.

@SergioDiniz
Created November 19, 2016 15:13
Show Gist options
  • Save SergioDiniz/ab36d4cb015f61d0d66e08a9651e47f3 to your computer and use it in GitHub Desktop.
Save SergioDiniz/ab36d4cb015f61d0d66e08a9651e47f3 to your computer and use it in GitHub Desktop.
private JasperPrint jasperPrint;
public void init() throws JRException{
JRBeanCollectionDataSource data = new JRBeanCollectionDataSource(listOfUser);
String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath(“report.jasper”);
jasperPrint = JasperFillManager.fillReport(reportPath, new HashMap<>(), data);
}
public void PDF() throws JRException, IOException{
init();
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
response.reset();
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment; filename=\"report.pdf\"");
ServletOutputStream stream = response.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, stream);
FacesContext.getCurrentInstance().responseComplete();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment