PDF from multiple tables
This is a work flow from the manual, based on an example from the telecom world.
Build Project and Service Work
The example is a tool supporting a service organization, which is building and upgrading sites, documenting each components configuration. An activity on a site is planned based on geographical information, and relevant access information for keys/codes etcetera. Before the activity is started the NOC is contacted for disarming the site. Performing the activity includes taking a before- and after picture on relevant components. It may also involve adjusting the configuration on one or more components. Afterwards it is possible to find all configuration for each site in the tool, as well as who did what and when. On a co-location site, the before- and after pictures are more important.
Preconditions
The information that ends up in a PDF is maintained in four tables. Basic information surrounding the site such as location is stored in Site. Each site is equipped with a set of components which are stored in Site Data. For each component, images are stored in Image. Contact information is stored in Contact.
A PDF can show related information for each Site, as well as pictures and graphs, in a highly customizable format. PDF are typically used as documentaion for deliveries. In a tabular report with multiple tables as source data the result is flattened an contains redundant information, since the information is consolidated into one table. However, even if the source data to a PDF is a flat table it is possible to present the underlying structure. Images and other graphical elements can also be included.
Template Creation
In the manual there is a guide on how to create a PDF template, starting with a Data Adapter. The Data Adapter will connect the information from IS Tools to fields in the template. In general, one Data Adapter is needed for every report template created in IS Tools.
If a Data Adapter is not selected during the creation of a report in Jaspersoft Studio it is possible to connect it afterwards. Right-click on the report name in the Outline panel, and select Dataset and Query.
In the Dataset and Query Dialog, the correct Data Adapter be selected, and the fields can be populated using Read Fields. After populating the fields the Class Type can be set, and this affects how the field is managed and shown. For file fields this needs to be set to java.io.File. Numeric fields can be set to java.lang.Double, since this allows for calculations.
When the fields have been populated they can be placed in the relevant band on the canvas. In this case however, the information will first be split into three groups - Site, Site Data and Image.
The fields under Fields in the Outline panel are data fields, and will be populated with data from the IS Tools Report associated with the Data Adapter during the creation. In some cases, such as when a field is put in the Detail Band, a corresponding label is also created as a Static Text Element in the Column Header Band.
Splitting the information is done using Create Group, where the information is grouped either by a field or by an expression. In this case Site is a record name for a site, and Site Data is the record name for a component.
Each group creates one or two bands for the group: Group Header och - Footer. In this case only Header will be used. In this band the fields belonging to the group are placed.
For Site and the band Site Group Header 1 the fields Site (record name), Latitude and Longitude are used. It is also possible to add contact details to the NOC or for site access.
For Site Data and the band Site Data Header 1 the fields Site Data (record name), Azimuth and Center Frequency are used. Also in this case it is possible to include other fields belonging to the group Site Data.
To simplify the design of the report, the Frame element is placed in the band. A frame can be used for different thiings, but here it is used to group the related fields.
A Frame has its own layout setting, which may be set to something else than that of the band. To arrange the fields in a row for instance, the Horizontal Layout can be used. Once populated, it can be reset to Free Layout.
Elements, such as Frame, can be easily arranged and sized to the band. In this case Fit Both was selected, and then the height of the Frame was set in the properties panel. It is possible to select and set for multiple elements at once. The fields can then be placed in the Frame.
When placing grouped fields it will prompt for a calculation. In this case no calculation is selected. This dialog will present different options depending on Class Type.
When having placed the fields the Print When Expression option may have to be set to hide empty rows. The setting depends on the field's Class Type, in this case java.lang.String.
The expression shown in the screen clip:new Boolean($F{Image} != "")
When testing the report it is easy to spot which bands are needed and which can be removed. When removing a band from the canvas it can be put back by comparing a similar blank report with all bands present and then using the Source view to copy and paste relevant parts.
The result after more additions and adjustmentes. To adjust the text in the fields, and to add padding often make a big difference. If all text fields are selected, it is simple to set the same value for all at once.
Summary
A PDF is based on tabular information, which with a Data Adapter is transformed to fields, which in turn can be displayed in various ways. Pictures and other graphical elements can also be included. If the information is sourced from multiple tables one can use grouping to show or use the underlying hierarchy.