> Hi,
>
[quoted text clipped - 21 lines]
>
> Dimitri Kouroukidis
Is it so hard to read the example programs for this?
I
1. take your iReport.xml file
2. run it thru the Jasper report library.
the following code sample will process a report file "report3x4.xml" ( no
this is not with the libraries you have to lay it out yourself, and is my
layout)
just do an IReport with a simple text field "hello world"
You will also need the Itext libraries to handle the pdf conversion.
HERE IS SOME SAMPLE CODE, THIS WORKS as it is extracted from a current
project.
It ensures the xml report is re-compiled each time.
Finally to get data from a database you must build a custom data source,
which runs to about 10 lines of java code. I'm already doing the same with
oracle.
Map parameters = new HashMap();
//strings in the "" are the names of the jasper report fields.
parameters.put("ReportTitle", Header[0]);
parameters.put("FactoryName", Header[1]);
String PrintType="P.D.F";
//String PrintType="!P.D.F";
//this sets up the base footer
//note that the strings it the "", are the names of the fields on the jasper
//reports, for this test you can strip out the " parameters" code.
//this sets up the base footer and pulls the stuff from an array
//setup some place else, the array contains Strings
parameters.put("thspg", Footer[0]);
parameters.put("pgcnt", Footer[1]);
parameters.put("thsdate", Footer[2]);
parameters.put("auth", Footer[3]);
parameters.put("docidx", Footer[4]);
parameters.put("repidx", Footer[5]);
parameters.put("draft", Footer[6]);
//this sets up the base footer
parameters.put("thspgttl", FooterTitles[0]);
parameters.put("pgcntttl", FooterTitles[1]);
parameters.put("thsdatettl", FooterTitles[2]);
parameters.put("authttl", FooterTitles[3]);
parameters.put("docidxttl", FooterTitles[4]);
parameters.put("repidxttl", FooterTitles[5]);
parameters.put("draftttl", FooterTitles[6]);
parameters.put("thspg", Footer[0]);
parameters.put("pgcnt", Footer[1]);
parameters.put("thsdate", Footer[2]);
parameters.put("auth", Footer[3]);
parameters.put("docidx", Footer[4]);
parameters.put("repidx", Footer[5]);
parameters.put("draft", Footer[6]);
//this sets up the base footer
parameters.put("thspgttl", FooterTitles[0]);
parameters.put("pgcntttl", FooterTitles[1]);
parameters.put("thsdatettl", FooterTitles[2]);
parameters.put("authttl", FooterTitles[3]);
parameters.put("docidxttl", FooterTitles[4]);
parameters.put("repidxttl", FooterTitles[5]);
parameters.put("draftttl", FooterTitles[6]);
try {
String RawfileName = "report3x4.xml";
//pre-compile the report, use default extension of "jasper"
JasperCompileManager.compileReportToFile(RawfileName);
String CompiledfileName = "report3x4.jasper";
JasperFillManager.fillReportToFile(CompiledfileName, parameters,
new CustomDataSource(data));
String PsudocodefileName = "report3x4.jrprint";
String finaloutputfileName = "Final_report.pdf";
if (PrintType.equalsIgnoreCase("P.D.F")) {
JasperExportManager.exportReportToPdfFile(PsudocodefileName,
finaloutputfileName);
} else {
//just print it out to the normal printer
JasperPrintManager.printReport(PsudocodefileName, true);
}
} catch (JRException e) {
Error_stuff.Error_funcs.handleError(e, -1, -1);
e.printStackTrace();
}
}