I am trying to create jasper reports in my java Spring web project. I have already tried the method I am using in a javaSE application and it worked fine.
But in my web project I am facing some difficulties. The issue is bit strange and I cannot figure it out.
this is my code.
try {
net.sf.jasperreports.engine.design.JasperDesign design = JRXmlLoader.load(
new LegacyJasperInputStream(new FileInputStream("C:/Users/mypc/Desktop/letter3/a/testreport.jrxml"))
);
JasperReport jasperReport = JasperCompileManager.compileReport(design);
JasperPrint print = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
System.out.println("INFO: Report is filled and to be exported to pdf now");
try {
// export report to pdf
JasperExportManager.exportReportToPdfFile(print, "C:/Users/mypc/Desktop/letter3/a/test.pdf");
System.out.println("DEBUG: Expported to pdf");
} catch (Exception e) {
System.out.println("EXCEPTION: while exporting to pdf : "+e);
}
} catch (Exception e) {
System.out.println("EXCEPTION:while generating report: \n"+e);
}
System.out.println("DEBUG: check point is reached!");
it works without any exception, but generates an empty pdf. The strange thing is it prints following line (it is before the exporting to pdf section) in the console, but nothing after that.
INFO: Report is filled and to be exported to pdf now
if an exception is occurred in the process of exporting to pdf, it should be shown in the console as I coded as needed like this in above code.
catch (Exception e) {
System.out.println("EXCEPTION: while exporting to pdf : "+e);
}
But no exception is shown and code does not go forward after this point. If no exception is occured, it should print
System.out.println("DEBUG: check point is reached!");
in the console.
Why is this. I am confused. It generates a empty pdf. I have added the font to the classpath as a jar.
Thank you!
Aucun commentaire:
Enregistrer un commentaire