Jasper报告导出到.PDF文件

时间:2017-08-29 14:41:55

标签: java jasper-reports

当我尝试导出Jasper Reports时,我最终遇到了问题。其他人认为似乎没问题。

似乎是在出口时间

这是我的代码:

JasperReport jasperReport = null;
try {
    jasperReport = JasperCompileManager
            .compileReport("/home/ederson/Developer/temp/StyledTextReport/StyledTextReport.jrxml");
} catch (JRException e) {
    System.err.println("Erro ao tentar compilar Jasper Report" + e);
}

Map<String, Object> map = new HashMap<String, Object>();

JRDataSource dataSource = new JREmptyDataSource();

JasperPrint jasperPrint = null;
try {

    jasperPrint = JasperFillManager.fillReport("output" + ".jasper", map, dataSource);
} catch (JRException e) {
    System.err.println("Erro ao tirar o print" + e);
}

File output = new File("/home/ederson/Developer/temp/output");
output.mkdirs();

// PDF Exportor.
JRPdfExporter exporter = new JRPdfExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

try {
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, new FileOutputStream("output" + ".pdf"));
} catch (FileNotFoundException e) {

    System.err.println("Erro ao exportar");
} // your output goes here

exporter.exportReport();

System.out.print("Done!");

这是我的痕迹:

Exception in thread "main" net.sf.jasperreports.engine.JRException: No input source supplied to the exporter.
    at net.sf.jasperreports.engine.JRAbstractExporter.setInput(JRAbstractExporter.java:845)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:259)
    at br.com.jReport.Run.main(Run.java:58)

0 个答案:

没有答案