Reportmill Tutorial: Template Design Basics
Reportmill Tutorial: Template Design Basics
Table of Contents
Page Headers/Footers 0 Substitution Keys 0 XML Based Template Design 0 List Keys and Tables 0 Tables 0 Formatting 0 Table Grouping 0 Table Sorting 0 The Attributes Panel 0 The Inspector Panel 0 App Server Integration
0
Page Headers/Footers
Overview
ReportMill's core is a page layout application, providing instant familiarity with template design basics. Users can simply draw page headers/footers, cover/summary pages, etc., using the common tools:
0 0 0 0 0 0 0 0
Selection Line segment Rectangle (with rounding) Oval (with sweep, start angle) Text (with powerful rich text editing) Polygon (click to add points) Star (really any n-sided symmetric polygon) Pencil (with curve fitting)
Additionally, images, such as company logos can be added to a template via drag and drop. ReportMill accepts images in many formats: GIF, JPEG, PNG, TIFF, BMP and PDF. Step 1: Select the text tool, click in the upper left corner of the page and type "Movies Database". Step 2: Use the mouse to select the text you've just typed in (or the menu Edit->Select All), then bring up the font panel using the menu Tools->Font Panel (or use the menu accelerator, control-t). Select a font, font size, font style that appeals to you. Step 3: Drag and drop an image from your desktop into an empty region of the template (dropping it on the existing text would give you the option of creating a texture, which is not what we want here). You can probably find an image quickly using your web browser.
Substitution Keys
Overview
ReportMill performs key substitution using the familiar mail-merge paradigm of surrounding keys by the "@" character, making it easy to mix static text and substituted data. Predefined keys such as "@Date@" and "@Page@" are readily available from the Keys Browser - or they can simply be typed in. An example of mixed text and keys is "Today's Date: @Date@". Additionally, keys can be in the form of mathematical expressions, to perform calculations (eg, @budget/revenue*100@). We'll see how to bind to XML and Java object data on the next page. Step 1: Bring up the keys panel using the menu item Tools->Keys Panel. Step 2: Drag and drop the key "Date" from the keys panel to the document. Step 3: Position and size the Date text field, so it will be big enough to hold some static text and the substituted date value (you can change the font, too, using the font panel). Step 4: Double-click on the field and add the text "Today's Date: " before the existing "@Date@". Step 5: Bring the Keys Panel up again (you can also use the menu accelerator, Control-k), then drag the key "@Page@ of @PageMax@" to the bottom margin of the page. Step 6: Hit the "Preview" button at the upper left corner of the document to see a preview of the Date and Page keys. Don't forget to hit that button again (it now says "Edit") before you continue.
Tables
Overview
The table template is a grey box with a single "Movies Details" row at the top (pre-configured with four columns). Position and size the table template to cover the region of the page that you want the objects to cover (this generally means making the table almost the size of the whole page). The Keys Browser now shows all of the keys relevant to an individual Movie (it will do this as long as the table or one of it's children is selected, otherwise it will show the root of the XML file again). Drag and drop keys for the movie into the columns of the table. Make sure the border of the column lights up, otherwise your key might end up just above the table, instead of inside it (in which case it won't get repeated). Step 1: Position and size the table template to cover most of the page. Step 2: Drag the "title" key into the first column. Step 3: Drag the "dateReleased" key into the second column. Step 4: Drag the "revenue" key into the third column. Step 5: (optional) Click in the final column and drag it outside the bounds of the table to get rid of it. You can add additional columns in the table row inspector (covered later). Step 6: Hit the "Preview" button to see a real, paginated "Movies" report!
Formatting
Overview
ReportMill offers many formatting options, including sizing, font selection, color selection, text alignment, money/date formatting, etc. Step 1: Click in the column with the "@revenue@" key and select all text. Step 2: Bring up the Formatter panel using the menu Tools->Formatter Panel (or the menu accelerator control-f). Choose the second button in this panel (the money formatter). Choose the second format: Money, rounded to the nearest dollar. Step 3: Bring up the shape-specific inspector by using the menu Tools->Inspector. This should be the text inspector. Align text to the right by clicking the third button (it has the stacked bars icon, with the bars all aligned to the right). Step 4: Back in the document window, select the resize bar just to the left of the "@revenue@" key and move it to the right so the column is thinner. Step 5: (Optional) Select the resize bar under the whole table row and move it up or down to make each row taller or shorter.
Tables: Grouping
Overview
It's often a requirement of tabular reports that the data be broken down and separated by specific attributes. ReportMill makes this trivial, by continuing with the drag and drop theme. By simply dragging any attribute from the Keys Browser into the Table Inspectors "Grouping" list, you effectively group all of the List key objects by that attribute - and the table template gets a new row to configure for each added grouping. Note: You can insert an explicit page break after any grouping (say after each studio) by clicking the grey box to the right of that grouping. Step 1: Make sure the table is selected and drag the "studio" key from the Keys Browser to the "Grouping" list in the Table Inspector. Step 2: Navigate to the key "studio.name" and drag it into the first column of the new "Studio Details" row. Step 3: Navigate to the key "total.revenue" and drag it into the last column of the Studio Details row. Step 4: Format the keys in the new "Studio Details" row by selecting the text and making it bold (also align the "total.revenue" key to the right and add the money formatter like we did in the previous page). Step 5: (Optional) Select the table row by clicking (or double-clicking) on it's resize bar, then choose a background color (bring up the Color Panel with the menu Tools->Color Panel).
Tables: Sorting
Overview
Another common requirement of tabular reports is sorting. Once again this is made trivial by dragging keys from the Keys Browser to the Table Inspector's "Sortings" list. In this case, however, you can provide a list of keys for each level of grouping. The "studio" grouping, for instance might have the sort "total.revenue" so that the most successful studios are listed first. And the Movie level might have the sort "revenue" and "title" so that the most successful movies for each studio are listed first (alphabetically, by title, when there is a tie for revenue). Note: the sorts each have a "ABC/123" button to the right of them, indicating Ascending vs Descending sorts. Click this when you want to change the order (which would be the case for the revenue keys). Step 1: Make sure the table is selected and the "studio" grouping is selected, then navigate to the "total.revenue" key and drag it into the Table Inspector's "Sortings" list. Click the "Ascending/Descending" button to get the "321" setting. Step 2: Make sure the "Movies" grouping is selected, then drag the "revenue" and "title" keys into the "Sorting" list. Make sure revenue is "Descending". Step 3: Click Preview to see a report of the most successful studios and movies in Hollywood!
Shape Specific
Fill/Stroke
Location/ Size
Rotation/ Scale
Animation
ReportMill.jar
The first thing to note is that ReportMill is a simple jar file - simply add ReportMill.jar to the classpath on your developer and deployment machines and any Java servlet, batch process or command line tool can turn objects into PDF and Flash. This is far superior to reporting tools that run on a separate machine or a separate process, because it removes a point of failure and saves the wasted time and memory of refetching the current Java dataset.
The API
To turn Java objects into PDF, you simply call the following lines of code - from absolutely any part of any Java application: // Load template from any Source (File, String path, InputStream, byte array, etc.) RMDocument template = new RMDocument(aSource); // Generate report with EJBs, POJOs, Java Collections, JDBC ResultSet, etc. RMDocument report = template.generateReport(myJavaDataset); // Get PDF (or HTML, Flash, Excel, XML, etc.) byte pdf[] = report.getBytesPDF();