Book Image

JasperReports 3.6 Development Cookbook

By : Bilal Siddiqui
Book Image

JasperReports 3.6 Development Cookbook

By: Bilal Siddiqui

Overview of this book

<p>JasperReports is the world's most popular embeddable Java open source reporting library, providing Java developers with the power to easily create rich print and web reports. While such reports are pivotal in managing business information more effectively, creating and customizing them can get tedious.<br /><br />This book will give you recipes to solve common JasperReports problems to make your life easier. It will take you through complex examples related to JasperReports with step-by-step instructions on how to solve them.<br /><br />The author's experience in creating reports enables him to share over 50 recipes to develop crystal-clear business reports using the capabilities of JasperReports and the amazing features provided by its visual report designer tool: iReport.<br /><br />This cookbook will arm you to develop user-friendly reports by using multiple types of data in the same report, thereby saving your time in sorting, arranging, or extracting data and making the whole process effortless. First you will learn to do basic things such as creating, sizing, positioning, and enhancing the titles, headers, footers of the report. You will move on to working with the body and footer of the report, including using parameters to filter records during report processing and implementing nested hierarchy. Second, you will learn to enhance the look and feel of your report by deploying and reusing styles, and by using designs, textual effects, background images, and watermarks. You will also learn to use mathematical and logical expressions such as counting the number of records with a particular field value, grouping records, applying styles on your data based on logical or mathematical conditions, and so on.<br /><br />Then you will be able to do advanced things such as working with a variety of data sources: relational data, XML data, model beans of Java applications, and also multiple relational databases at once. You will learn to build a cover page and table of contents for multi-page reports, display multi-dimensional page numbering, and much more. You will be able to design simple and multi-level summary reports, cross-tabs with dynamic rows and columns, create bar charts, and display data trend graphs in your reports. Lastly and very importantly, you will be able to generate reports from Java Swing applications after you learn how to use JavaWrappers for your JasperReport.</p>
Table of Contents (13 chapters)
JasperReports 3.6 Development Cookbook
Credits
About the Author
About the Reviewers
Preface

Preface

JasperReports is the world's most popular embeddable Java open source reporting library, providing Java developers with the power to easily create rich print and web reports. While such reports are pivotal in managing business information more effectively, creating and customizing them can get tedious.

This book will give you recipes to solve common JasperReports problems to make your life easier. It will take you through complex examples related to JasperReports with step-by-step instructions on how to solve them.

The author's experience in creating reports enables him to share over 50 recipes to develop crystal-clear business reports using the capabilities of JasperReports and the amazing features provided by its visual report designer tool: iReport.

Create and enhance your business reports using the various functionalities of JasperReports and iReport.

What this book covers

Chapter 1, Creating Static and Dynamic Titles and Headers, focuses on basic things such as creating, sizing, positioning, and enhancing the titles and headers of the report.

Chapter 2, Working with the Body and Footer of your Report, covers working with the body and footer of the report, including using parameters to filter records during report processing and implementing nested hierarchy.

Chapter 3, Enhancing the Look and Feel of your Report, shows you how to enhance the look and feel of your report by deploying and reusing styles, and by using designs, textual effects, background images, and watermarks.

Chapter 4, Working with a Variety of Data Sources, focuses on advanced things such as working with a variety of data sources: relational data, XML data, model beans of Java applications, and also multiple relational databases at once.

Chapter 5, Multi-page Reports, teaches you to build a cover page and table of contents for multi-page reports, conditional reset page numbering, display multi-dimensional page numbering, design multi-page reports using sub-reports, create separate header and footer for each sub-report in your Master report, and much more.

Chapter 6, Multi-column Reports, covers topics such as dividing the body of a report in multiple columns, grouping records with common value in a report column, filling data in report columns horizontally and vertically, inserting column break in your report, controlling the size of each column independently, and using sub-reports to design multi-column reports.

Chapter 7, Summary Report, Crosstabs, and Graphs, covers designing simple and multi-level summary reports, cross-tabs with dynamic rows and columns, creating bar charts, embedding a bar inside a tabular view, and displaying data trend graphs in your reports.

Chapter 8, Java Wrappers for your JasperReports, covers generating a report from a Java Swing application, generating a report from your web application, printing a hard copy of a report on the fly from within your Java code, viewing your report as a PDF, or a web page, or an XLS sheet, and so on.

Chapter 9, Using Mathematical and Logical Expressions, covers mathematical and logical expressions such as counting the number of records with a particular field value, grouping records, applying styles to your data based on logical or mathematical conditions, and so on.

Note

Chapter 9, Using Mathematical and Logical Expressions, is not present in the book but is available as a free download from: http://www.packtpub.com/sites/default/files/downloads/0769os-chapter-9.zip

What you need for this book

The following software products are used in this JasperReports 3.6 Development Cookbook:

  • JasperReports version 3.6.0

  • iReport version 3.6.0

  • PostgreSQL version 8.4

  • Apache Tomcat version 6.0.16

  • Java Development Kit (JDK) version 1.6.0_12

Who this book is for

This book is for Java developers who want to use JasperReports to create user-friendly business reports. It is for those who may be familiar with JasperReports but want to dive into advanced JasperReports activities.

If you know how to use Microsoft Word, you can also learn how to design business reports using iReport by following the recipes of this cookbook.

Although the primary audiences of this cookbook are report designers, Java and XML developers will find this book useful in understanding how Jasper's XML code works and how to wrap JasperReports functionality in your Java Swing or web applications.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: Open the Pattern.jrxml file from the Task5 folder in the source code for this chapter.

A block of code is set as follows:

<staticText>
<reportElement x="107" y="10" width="340" height="33"/>
<textElement>
<font fontName="Verdana" size="24"/>
</textElement>
<text><![CDATA[Monthly Customer Invoices]]></text>
</staticText>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<jasperReport
<title>
<band height="94" splitType="Stretch">
<!-- other JasperReports XML tags -->
<image>
<reportElement x="365" y="10" width="180" height="80"/>
<imageExpression class="java.lang.String">
<![CDATA["X:\\Images\\packt.png"]]>
</imageExpression>
</image>
</band>
</title>
<!-- other JasperReports XML tags -->
</jasperReport>

Any command-line input or output is written as follows:

uncompress iReport-nb-xx.tar.gz

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Select Currency from the Category column and click the OK button."

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an email to, and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book on, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Note

Downloading the example code for the book

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration, and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to any list of existing errata. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or web site name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.