Printable reports
  • 25 Oct 2023
  • 5 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Printable reports

  • Dark
    Light
  • PDF

Article Summary

1. Studio download and installation

  1. Take the final version 6.17.0: https://community.jaspersoft.com/community-download
  2. Download and install.

2. Create a more detailed report of your schemas

In this documentation, we demonstrate how to create a report on a schema. In view of this demonstration, we will create a report on a task called "Consultation" including documents and folders that must be consulted by a user. This report will include the task, its identifier and title, the date of creation, and the list of folders and documents.

2.1 Create the consultation task

  1. In Constellio, create a task assigned to a user;
  2. Add linked folders and linked documents.

2.2 Search for XML for task-based tests

  1. Go get an XML to have the attributes that will be on your report.
    1. Go to " Administration ";
    2. Go into printable management;
    3. Open report management;
    4. Open the tasks tab;
    5. Select XML for reporting;
    6. Search for the test consultation task that you created in the previous section and made " Select ";
    7. Press " Save ".
  2. An XML file will be downloaded to your computer. You can view the contents of your XML with software like "Notepad++" or simply with a browser.

3. Create your label project on JasperSoft studio

  1. Open JasperSoft studio;
  2. Make File -> New -> Jasper Report;
  3. In the " templates" choices, take " Blank Letter ". Click " Next ";
  4. Choose the name of your jrxml file and the location of the project in your workspace. Click " Next ";
  5. Create a new adapter (give a meaningful name like Task Adapter);
    1. In the adapter creation window, take XML document and click " Next ";
    2. Give a name, choose the location the file created in XML in the previous chapter is located and choose the option " Xpath expression ";
    3. Click " Finish ".
  6. Move down the tree and choose " UserTask " (double-click). Click " Next ". (Or finish if you want the XML elements to be accessible and you don't need the order of the documents to generate the printable);
  7. Click " Finish ".

4. The form of the draft report

In the design, we can see the project is separated into several sections.

Sections

ImageDescription
TitleFor those who want a title page.
Page headerIt will be displayed at the top of the page on each page.
Detail 1Detail section. You can do other sections, it is advisable to make separate sections to avoid problems.
FooterWhat is displayed all the time at the footers of the page (Page number, signature, print date, etc.)
SummaryWhat you want to display last (a summary, conclusion, etc.)
Column Footer/Column HeaderFor reports that are only a large table (not in the case of the present example).
Remove unnecessary items
You can remove items that are not useful by right-clicking and deleting them in the Project Outline.



5. Elements of the basic report

  1. First, please frame the display area of your metadata fields. Use the frame element of the palette. Framing it will limit the borders and put the borders. You can put display expressions too;
  2. The metadata is in your " fields " list in the Outline. However, there is reference metadata that is lower in the task hierarchy.
    For example, there may be an assigned user in connection with the task. So <> will have a tag inside <User>.
    If you want the username metadata, " Create a field " in the outline field list (right click -> Create fields) and you put in the description of the field its XML path (./assinee/User/username) and the field will know where the value is printed.
    (Attention! The path may be different, refer to XML to find out where it is).
  3. You can drag and drop your fields into the report, or create the field from the " Text Field" palette.
    For titles or labels that do not change, you can use " Static Text ".
    Some fields that you will use may contain nothing. (Example: folder without closing date, the closing date field will be "null"). In this case, instead of having a field with the value "$F{date}" put the following:  
    $F{date} !=null && ! $F{date}.equals("null")? $F{date}: ""
  4. Don't forget to save (Ctrl+S) and save your project;
  5. You can watch the result with preview.

6. Create a table

  1. In the palette, take the table, and create the table in your detail strip. It is recommended to have a separate band;
  2. Take a table with a new dataset and create an empty data set;
  3. Leave the connection to the last choice. Press " Finish the wizard ";
  4. Once finished, there will be a basic table. You can open a tab of the table and its elements by double clicking on it;
  5. You will have several sections:
    1. To make a minimal table, I will remove the table legs, table header, and column legs. You can add a column by right-clicking on the header and taking the add column option;
    2. You can change the style by right-clicking the table and taking the " change table style " option;
    3. Adjust the widths of the columns as desired. Add " A column cell " and go to the property of " cell " and put the width. You can insert the labels of the columns;
    4. To have the metadata elements of the task folders, you must change the dataset of the table. Simply go back to the draft report and click on the table once; In Dataset, we change to JRDatasource and insert the following line:
      ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE})
      .subDataSource("//linkedDocuments/Document")
    5. "//linkedDocuments/Document" is the link to the object processed in the table. For documents linked to a task, it would be that path. Check in the XML the path for the other schema lists you want; 
    6. You can create your fields manually, simply go to the list of fields in the table and add them manually (right-click and create fields). Follow the format of this next image so that the field accesses the value;
    7. Previewing gives you a taste of the result. Also, you can export a PDF or a word;

7. Add pagination

  1. In the " Elements composites ", take the " Page number" element . You can simply drag it into the footer;

8. Put an image

  1. Take from the palette an image element;
  2. Click and make the size and width with the mouse in the design. Take the " No image " option;
  3. Go to property and put the following line in the image expression.

net.sf.jasperreports.engine.util.JRImageLoader.getInstance(new SimpleJasperReportsContext()).loadAwtImageFromBytes(javax.xml.bind.DatatypeConverter.parseBase64Binary("YOUR BASE64 HERE"))


8.1 Retrieve base64 of the image

  1. If you have your image, go to the following site: https://www.base64-image.de/
    If you have a better site to convert an image to base64, do as you please. Take a PNG or JPEG, otherwise, there will be display problems.
  2. Drag the image and press " show code " when the conversion is complete. Copy and paste the Base64 code by removing the elements before the first comma;
  3. Press " copy to clipboard " to copy;
    You can remove the part to be removed only after copying and pasting it elsewhere.
  4. Paste the base64 into the part in quotation marks where you just deleted before the comma.
  5. You can check that it works with " preview ";

8.2 Jasper file

  1. Go to Project -> Build All;
  2. A jasper file will be created in your working folder of the labels chosen at the beginning of the project (where the .jrxml project file is located);
  3. In Constellio, return to report management and click " Add Report Template ";
  4. Fill in the fields and add the Jasper file;
  5. Tap " save ".

You could print the task reports now.


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.