JasperReports Library is an open source reporting engine, written entirely in Java. JasperReports Library is able to use data coming from any kind of data source and produce documents that can viewed, printed, or exported in a variety of document formats, including HTML, PDF, Excel, OpenOffice and Word.
2. Content
• What Is Report
• Introduction Of Jasper Reports
• Structure Of Report Template
• Features Of Jasper Reports
• Jasper Reports LifeCycle
• Some Classes Use To Create A Jasper Reports
• Useful Element To Represent Values In A Jasper Report
• How To Create Jasper Report Design
• Virtualizers(Generating Very Large Documents Using Report Virtualizers)
• Our Agenda
3. What Is Report
• Reports represent usual messy data into charts, graphs, and other
forms of graphical representations.
Introduction Of Jasper Reports
• First We should know JasperReports Is a java process
• It is an open source java reporting engine.
• It is a Java class library, and it is meant for those Java developers who need to add
reporting capabilities to their applications.
• In this tutorial we will covers almost all the basics of JasperReports that atleast a
beginner should know before working with JasperReports.
5. • Title contains the 'Title' of the report. It appears only once at the very beginning of the report.
For example, Title of the report is "Student Report"
• PageHeader may contain date and time information or organization name. This appears at the top of each
page.
For example: Page header heading will be “Student Records”
• ColumnHeader lists the names of those specific fields, which you want to display in the report,
For example, "Student Id," "Student Name," "Student Address" etc.
• Detail is the part where entries of the specific fields are shown,
For example Student Id=101, Student Name="Den Peek", Student Address="Pune"
• ColumnFooter may display Sum of any of the field
For example, "Total Hours Study: 6 hours in a day"
• PageFooter may contain page count information. It appears at the bottom of each page,
For example, "Page Number is 1,2,3 and all"
Structure Of Report Template
6. Features Of Jasper Reports
• Some of the significant features of JasperReports are −
• It has a flexible report layout.
• It can present data either textually or graphically.
• Developers can supply data in multiple ways.
• It can accept data from the multiple data sources.
• It can generate watermarks
• It can generate sub reports.
• It is capable of exporting reports in a variety of formats.
like(PDF,XML,CSV,HTML,XLS,etc)
7. Jasper Reports LifeCycle
The main purpose of JasperReports is to create- page oriented, ready to print documents in a simple
and flexible manner-:
Step1)Designing the report − In this step we, create the JRXML file, which is an XML document that
contains the definition of the report layout, we have some tools to design report are like (jaspersoft
studio & iReport Designer)
Step2)Compiling the report − In this step, JRXML is compiled in a binary object called a Jasper file with
extension (*.jasper). This compilation is done for performance reasons.
Step3)Executing the report (Filling data into the report) − In this step, data from the application is filled
in the compiled report. We have a class name JasperFillManager provides necessary functions to fill the
data in the reports. A Jasper print file with extension (.jrprint) is created, which can be used either to
print or export the report.
Step4)Exporting the report to desired format − In this step, we can export the Jasper report file to any
format using JasperExportManager class.
Jasper provides various forms of exports with the same jasper design like (PDF,XML,CSV,HTML,XLS,etc..)
8. Some Classes Use To Create A Jasper Reports
There are number of classes, which will be used to compile a JRXML report design, to fill a report, to print a report, to export to PDF,
HTML & XML files etc.
Which are present in(net.sf.jasperreports.engine) package
• JasperCompileManager − Used to compile a JRXML report template.
• JasperFillManager − Used to fill a report with data from the data source.
• JasperPrintManager − Used to print the documents generated by the JasperReports library.
• JasperExportManager − Used to obtain PDF, HTML, or XML content for the documents produced by the report-filling process.
9. Useful Element To Represent Values In A Jasper Report
Parameter: $P
$P{parameter_name}
-it is used for single values on the report
-The data which cannot be passed through the data source, can be passed by using parameters. Data like title of the report, etc.
-A JasperReports template or JRXML template can have zero or more parameter elements.
Field: $F
$F{field_name}
-Report fields are elements, which represent mapping of data between datasource and report template.
-it is used to change the value on every iteration
-or we can say it is used to represent a row data in the table
Variable: $V
$V{variable_name}
-it is provided by jasper report.
-it is also used to perform some calculation on jasper report like arithmetic operations,etc.
10. How To Create Jasper Report Design
Steps To Design And Genrate A Jasper Reports Are As Follows-:
- Design-: For Design Or Create A Jasper Report We Will Use Tibco Jaspersoft Studio Tool
- Copy Report To Project-: Copy That Report Format To Your Java Project
- Dependency-: Add JasperSoft Dependency To Your Java Project
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.9.0</version>
</dependency>
- Read that jasper report file in java program
- Compile The Report
- Create A Datasource
- Pass That Datasource To FILLMANAGER to Fill That Report
- Export The Report In The Required Format
- But Before Moving Forward You May Get An OutOfMemoryError If You Have Huge Amount Of Data So We Will Overcome With
This Problem With The Help Of Virtualizer So We Will Discuss First What Is Virutalizer.
11. Generating Very Large Documents Using Report Virtualizers
Why We Need A Virtualization?
-A Jasper Report Goes Through 3 Stages In His LifeCycle Compilation, Filling, Exporting
-In each stage objects are generated in memory. During the filling stages especially many no of objects
can be generated if you have large amount of data.
-In this situation, there is always the risk of getting an Out of Memory error before the Filling
of the report has concluded. To overcome from this problem we will use Virtualizers.
What is Virtualization?
Virtualization is a feature that allows for some of the objects that would be stored in memory during
the filling stage to be stored on the file system instead.
The virtualizer is a simple interface JRVirtualizer
So How To Use It?
-create the virtualizer JRFileVirtualizer virtualizer = new JRFileVirtualizer(2, "tmp");
The JRFileVirtualizer is created with a maxSize of 2 and "tmp" as the name of the directory to store data.
-Preparingparameters Map parameters = new HashMap();
parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
12. Our Agenda
We Will Create A Sample Of Jasper Report-:
We Have Some Student Records In database-:
We Will Design A Jasper Report And Represent All The Records In Jasper Report In Format Of PDF,HTML & XML