Jump to content
We've recently updated our Privacy Statement, available here ×

  • Giulio Toffoli
    • Product: iReport Designer

    by Giulio Toffoli

    When the user creates a new port, the template chooser proposes several ready to use documents to choose from.

    These documents can be taken as they are, or can be used with the wizard to create proper textfields, labels and groups starting from an SQL query or another data source.

    In this tutorial we will see how to create a custom template and add it to the template chooser.

    figure_1.png.434a5391aabde7f2ad1dbf1df4d42ba8.png

    All the templates shown in the template chooser are simple JRXML files. We can start with a blank report and add some elements to create the template we have in mind.
    Almost all the templates in iReport use A4 as page format.

    To change it, click Format → Page format and set the page size you prefer.

    figure_2.png.115c9b961ae5a534b098da3a4b8cd210.png

    When the report is ready, add it to the list of templates from Tools → Options → iReport → Wizard Templates. Here you can add a single jrxml or an entire directory. All the jrxml files present in the directory will be loaded and proposed as templates. If you plan to use images in your template, save the images in the same location as the report, and reference the image in the report just with the image name (i.e. use as image expression "my_logo.png" instead of referencing a complete path). In this way, when the template will be used, iReport will create a copy of the image for the new report.

    figure_3.png.8370831cf70625bf70e9cf330e64ab54.png

    To create a thumbnail to be used in the templates chooser, preview your report and click the button displaying a chack (see figure 4). This will allows to save an image of the first page of the report.

    figure_4.png.7969a3c0b33abfcddc94d8de33e873a9.png

    Save the image in the same directory and with the same name (except for the extension) as your report.
    Creating a new file, you will find your new template in the template chooser.

    figure_5.png.e97d82d0415013332dadfa526987f25a.png

    Using the template with the report wizard

    The report wizard can leverage a template file by populating it with fields and labels. In particular, when the user choose a set of fields by using the report wizard, a label and a textfield can be created automatically. A similar automatism is available to generate groups when the user choses to group data.

    By default the report wizard creates a tabular layout (see figure 6), where in the column header band are placed a set of labels for each field, and the fields are printed all in a single line like in a table.

    By setting the report property template.type to columnar, the report generator creates a columnar layout.

    figure_6.png.27eaa0cf33abc6121f76366a08ec59ee.png
    When the report is generated, the wizard looks for a textfield in the detail band with the expression "Field", the textfield is replicated for each field selected by the user during the wizard steps.

    Based on the type of the layout the wizards looks for a static text (a label) in the column header band (for tabular layout) or in the detail band (for columnar layout). The label must have as value the string Label.

    In the grouping step of the wizard, the user can define up to four groups. The templates can define all of them (the name is not actually important, but the wizard will look first for groups named Group1, Group2, etc...). In the group header band of each group it is possible to place a label with the text Label and a textfield with the expression "Field". If present the first will be replaced with the name of the field used to group data, while the second with the value of that field.

    The following layout is a sample of a typical tabular template. Note the label element in the column header and the textfield and detail band.

    figure_7.png.d70c6afebdc1256fab034b780ab048d9.png

    Executing the report wizard using this template and choosing two groups, it will be possible to create a report like the one below.

    figure_8.png.47381bc84ba0303c68d6636cbb23a5c3.png

    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...