- Print
- DarkLight
- PDF
1. Studio download and installation
- Take the final version 6.17.0: https://community.jaspersoft.com/community-download
- 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
- In Constellio, create a task assigned to a user;
- Add linked folders and linked documents.
2.2 Search for XML for task-based tests
- Go get an XML to have the attributes that will be on your report.
- Go to " Administration ";
- Go into printable management;
- Open report management;
- Open the tasks tab;
- Select XML for reporting;
- Search for the test consultation task that you created in the previous section and made " Select ";
- Press " Save ".
- 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
- Open JasperSoft studio;
- Make File -> New -> Jasper Report;
- In the " templates" choices, take " Blank Letter ". Click " Next ";
- Choose the name of your jrxml file and the location of the project in your workspace. Click " Next ";
- Create a new adapter (give a meaningful name like Task Adapter);
- In the adapter creation window, take XML document and click " Next ";
- Give a name, choose the location the file created in XML in the previous chapter is located and choose the option " Xpath expression ";
- Click " Finish ".
- 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);
- Click " Finish ".
4. The form of the draft report
In the design, we can see the project is separated into several sections.
Sections
Image | Description | |
---|---|---|
Title | For those who want a title page. | |
Page header | It will be displayed at the top of the page on each page. | |
Detail 1 | Detail section. You can do other sections, it is advisable to make separate sections to avoid problems. | |
Footer | What is displayed all the time at the footers of the page (Page number, signature, print date, etc.) | |
Summary | What you want to display last (a summary, conclusion, etc.) | |
Column Footer/Column Header | For reports that are only a large table (not in the case of the present example). |
5. Elements of the basic report
- 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;
- 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). - 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}: "" - Don't forget to save (Ctrl+S) and save your project;
- You can watch the result with preview.
6. Create a table
- In the palette, take the table, and create the table in your detail strip. It is recommended to have a separate band;
- Take a table with a new dataset and create an empty data set;
- Leave the connection to the last choice. Press " Finish the wizard ";
- Once finished, there will be a basic table. You can open a tab of the table and its elements by double clicking on it;
- You will have several sections:
- 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;
- You can change the style by right-clicking the table and taking the " change table style " option;
- 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;
- 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") - "//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;
- 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;
- Previewing gives you a taste of the result. Also, you can export a PDF or a word;
7. Add pagination
- In the " Elements composites ", take the " Page number" element . You can simply drag it into the footer;
8. Put an image
- Take from the palette an image element;
- Click and make the size and width with the mouse in the design. Take the " No image " option;
- 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
- 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. - 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;
- Press " copy to clipboard " to copy;
You can remove the part to be removed only after copying and pasting it elsewhere. - Paste the base64 into the part in quotation marks where you just deleted before the comma.
- You can check that it works with " preview ";
8.2 Jasper file
- Go to Project -> Build All;
- 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);
- In Constellio, return to report management and click " Add Report Template ";
- Fill in the fields and add the Jasper file;
- Tap " save ".
You could print the task reports now.