Skip to content

Instantly share code, notes, and snippets.

@vahidhedayati
Last active November 1, 2022 19:54
Show Gist options
  • Save vahidhedayati/5aff632f84e5a94be90867ce2af88e59 to your computer and use it in GitHub Desktop.
Save vahidhedayati/5aff632f84e5a94be90867ce2af88e59 to your computer and use it in GitHub Desktop.
jaspe produce pdf
public void jasperPDF(HttpServletResponse response) throws JRException, IOException {
//Compiled report
InputStream jasperStream = (InputStream) this.getClass().getResourceAsStream("/file.jasper");
//Adding attribute names
Map params = new HashMap<>();
params.put("id","123");
params.put("name","dd");
final JRBeanCollectionDataSource source = new JRBeanCollectionDataSource(myList);
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(jasperStream);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, source);
response.setContentType("application/x-pdf");
response.setHeader("Content-disposition", "inline; filename=some.pdf");
final ServletOutputStream outStream = response.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, outStream);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment