Create PDF with Python — Browser-based report template design

In the first part of this article series, Server side report generation, I explained the server side reasons to develop our own reporting framework and the overall requirements we aimed to fulfill. This article concentrates on the client side — in particular on report template design, testing and deploying report templates. I’ll again focus on differences between Jaspersoft Studio (I refer to it as Jasper or Jasper Client in this article) and our own report framework ReportBro.

1 Installation

Jasper uses a client application (based on Eclipse and therefore requires Java Runtime Environment JRE) which exists for most operating systems and has to be installed locally. After starting the application you are ready to create new report templates.

ReportBro Designer is a JavaScript plugin that can be integrated into your web application. While this requires a little bit more work initially, having an integrated template design tool has quite some benefits as you’ll find out reading on. The installation is straight forward by including some JavaScript libraries and initializing the Designer with some HTML and JavaScript code.

Place an empty div within the <body> of a web page:

<div id="reportbro"> </div>
Initialize ReportBro

<script type="text/javascript">
    const rb = new ReportBro(document.getElementById('reportbro'), {});

2 Report Designer functionality

The Jasper framework is very powerful and feature rich. Jasper Client supports charts, sub-reports and many complex elements. While its capabilities are extensive it sometimes makes creating simple reports more complicated than necessary. Data queries are an integral part of most reports in Jasper and hence a deep understanding and knowledge of SQL is essential. But even for some simple tasks, like printing the current page in the footer (page x/y), you need to be aware of different types of expression evaluation. For us, and probably most Jasper novices, this was quite difficult to understand and get right in the beginning.

Screenshot of Jaspersoft Studio Report Designer Jaspersoft Studio Report Designer

ReportBro, on the other hand, is optimized for simple reports, i.e. displaying data (text, tabular data or images) exactly as defined on a layout template. All parameters are passed to the report directly and therefore ReportBro doesn’t require SQL (or any other query language) knowledge to create a report. Additionally, by using the same data eliminates the risk of potential inconsistencies between displayed data in the web application and the printed report.

ReportBro allows to easily and quickly design reports with a perfect layout. Printing the current page in the footer is as simple as inserting predefined variables for current page and total page count. Even for generating Excel outputs no additional configuration is needed. A very clear structure allows for rapid learning and immediate results.

Screenshot of ReportBro Designer ReportBro Designer

3 Creating a report

A controller in our web application is responsible for creating reports. In case of Jasper the controller performs a web request to Jasper Server which is not accessible from outside. In the controller we also check if the user is actually authorized to request a designated report. In case of downloading multiple reports, e.g. in a merged pdf or as a zip-file, these various requests cause an overhead and result in poor performance.

ReportBro (being a Python library) allows us to directly generate all our reports in the Python web application controller. This omits overhead and results in noticeable faster report generation and display to the user.

4 Test data and testing reports

Test data can be specified as part of the report in both solutions. Usually in Jasper you’ll connect to a database, so you’ll need to have a data source available as well for testing purposes. This makes testing much more difficult, especially when using a different Jasper server and database for local testing.

In ReportBro all test data is contained within the report definition, test data for all kinds of parameters can be defined directly in the report. This simplifies testing a lot because a PDF/Excel preview (using test data of the report itself) can be generated and viewed without any external dependencies like a data source. The possibility to use and test parameters directly also enables to completely separate report template design from application development.

Screenshot showing PDF report template preview with test data in ReportBro Designer Template preview with test data

5 Updating reports

To update an existing report in Jasper you need to open it in the client application and upload it to the server then. This can be done within the Jasper Client once the server connection is initially configured. Because we have different reports for individual customers this task is not only tedious but also error prone. That’s why we created a script to automate the report upload, along with specific tasks to create all report units and reports for a new customer. However, this still doesn’t help with report versioning which can only be done directly on the Jasper server.

With ReportBro Designer being integrated seamlessly in the web application all we have to do is to update the report within the application. We even developed versioned reports in our application — which is fairly simple as the report template is a JSON object that can be stored inside our application database. This allows us to easily test and switch between different versions of a report.

Screenshot showing ReportBro report management as part of a web application Report management within our web application

6 Report updates by application users

Our goal has always been to allow our application users to perform some minor report changes themselves. E.g. sometimes they simply want to modify the layout, change text formatting or add static text to a template.

With Jasper this is basically impossible. The user would need technical know-how not only to get the current report file from the server and upload changes but also to actually do simple updates without taking the risk of corrupting the template itself. While our clients are generally apt in working with web applications they usually lack that particular kind of know-how.

As integral part of the web application ReportBro is directly available to users. ReportBro has a built-in admin mode functionality which allows disabling all parameter fields for users while still being able to test them. Hence, predefined parameters that are filled during report generation (and thus should not be altered by end-users of the designer) are untroubled by layout modifications. This enables our application users to perform basic report layout changes themselves and as a consequence it means less work for us :-)

Infographic combining Python and JavaScript for a reporting framework

ReportBro is the perfect fit for creating PDF in Python for reasons:
Native Python, lightweight and fast
Visual designer which can be embedded into a web application
State-of-the-art design tool with drag & drop and touch support
Support for text, line, images, tables, barcodes, manual page breaks, frames and sections
Capability to adapt layout and content details during runtime
and a lot more...

Want to find out more? See and try the demos.

This article is the second of a two part series. It has been revised from its first version, published on Oct 28, 2019 on Medium.
The first article, Create PDF with Python — Server side report generation, covers server side aspects that led us to developing our own reporting framework.

By the way, ReportBro is also available for everyone as open-source on github (see Download page). Star us on github if you like what you see!