Created
May 28, 2017 17:51
-
-
Save chingovan/8e80b227a47f61fc0644cb874e9259c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.blogspot.chingovan.firstreport; | |
import java.io.FileNotFoundException; | |
import java.util.HashMap; | |
import net.sf.jasperreports.engine.JRException; | |
import net.sf.jasperreports.engine.JasperCompileManager; | |
import net.sf.jasperreports.engine.JasperExportManager; | |
import net.sf.jasperreports.engine.JasperFillManager; | |
import net.sf.jasperreports.engine.JasperPrint; | |
import net.sf.jasperreports.engine.JasperReport; | |
import net.sf.jasperreports.engine.design.JasperDesign; | |
import net.sf.jasperreports.engine.xml.JRXmlLoader; | |
public class App { | |
public static void main(String[] args) throws FileNotFoundException { | |
try { | |
String reportTemplateFolder = App.class.getClassLoader().getResource("report-templates").getPath(); | |
System.out.println("reportTemplateFolder: " + reportTemplateFolder); | |
JasperDesign jasperDesign = JRXmlLoader.load(reportTemplateFolder + "/first-report.jrxml"); | |
JasperReport report = JasperCompileManager.compileReport(jasperDesign); | |
JasperPrint jasperPrint = JasperFillManager.fillReport(report, new HashMap<String, Object>()); | |
JasperExportManager.exportReportToHtmlFile(jasperPrint, "D:\\first-report.html"); | |
JasperExportManager.exportReportToPdfFile(jasperPrint, "D:\\first-report.pdf"); | |
} catch (JRException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment