Last active
November 1, 2022 19:54
-
-
Save vahidhedayati/5aff632f84e5a94be90867ce2af88e59 to your computer and use it in GitHub Desktop.
jaspe produce pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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