|
|
||||||||
Project Home |
Tracker |
Documents |
Tasks |
Source Code |
Discussions |
Reports |
File Releases |
Wiki |
Project Admin |
|||||||||||||
| wiki1117: IReportAndJasperReportsBasicConcepts |
Manual for iReport 0.2.0 and above< Back to the TOC3 iReport and JasperReports Basic Concepts 3 iReport and JasperReports Basic Concepts iReport is not useful without a library called JasperReports. This powerful library is one of the most advanced reporting engines available to the OpenSource community. Before starting to play with iReport, it's important to understand what iReport does and why. In this chapter, I'll explain some basic concepts on how JasperReports works, what iReport does using "jasper" itself and why it simplify the life of the user. 3.1 How JasperReports Works JasperReports works in a way similar to a compiler and an interpreter. (See fig. 3.1.) The user designs a report coding it in XML in agreement with tags and attributes defined in a file called jasperreports.dtd (part of JasperReports). Using XML, a user defines the entire report, describing where place texts, images, lines, rectangles, how to retrieve data, how to make certain calculations to show subtotals, etc...
Fig.3.1: How JasperReports Works This XML source file must be compiled in order to produce a real report. The compiled version of the source is named "jasper file" (it ends with .jasper). A jasper file is a compiled report source. When we have a jasper file, we need another thing in order to produce a report; we need data. This is not always true. In some cases, we could want to generate a report that doesn't show dynamic data, but i.e. only static text, but this can be reduced to a report that has only an empty record. To supply these records to the jasper engine, we need to present it using a special JasperReports specific interface named JRDataSource. A datasource + a jasper file = a print. A print can then be exported in many formats like PDF, HTML, XML, XLS, CVS, etc... The export will be done using special classes, the implement specific exporters. 3.2 Compilation and Export of Reports For a newbie, designing and creating the jasper file is the hardest work. When you have designed and compiled your jasper file, you can use the JasperReport library to dynamically fill your report in several enviroments like a web application (using i.e. Java servlet, but I have succesfully used JasperReports for generating PDF reports calling it from a PHP script...). Jasper makes available a special viewer to display a report preview, designed for swing based traditional Java applications. Fig.3.2: JasperReports can easily integrated in a Web application as in a java swing based program. 3.3 Our First Very Simple Report iReport provides JasperReports users a visual interface to build reports, generate jasper files and test prints. iReport was created as a development tool, but it can be used as an office tool to retreive and print data stored in a database, without passing through another application.
Fig.3.3: How JasperReports Works iReport can read and modify both jasper XML and jasper files. Through JasperReports, it's able to compile XML to jasper files and "run reports" to fill it using several types of JRDataSource and export the results to PDF,HTML,XLS,CSV,... To better understand how this works, we'll do a test. Follow these simple steps: 1. Open iReport and create a new empty document.
Fig.3.4: New report properties 2. Add to the title band a static text element.
Fig.3.5: Changing Font Size.... 3. Run the report (iReport will ask to save the file before it compiles it.)
Fig.3.6: The final report viewed with GhostView. In this session we have created a simple report, saved as XML file, compiled as jasper file, filled with an "EmptyDataSource" end exported in PDF. < Back to the TOC |
|
|