Creating any layout involves incorporating text elements. In addition to static text, you will likely pass string parameters to the report, apply styles, evaluate and conditionally print text, and utilize rich text fields.
In this tutorial you will learn to:
•Insert text elements containing static and dynamic strings
•Align and style text elements
•Use rich text
•Perform a simple evaluation
1. Insert simple text elements containing static and dynamic strings
Let's take the example of a letter. Since we are the sender, we can include our information as static text. However, we anticipate addressing various recipients, and the data for this will be obtained from an application. Therefore, we require text with parameters to dynamically include recipient information.
Drag & drop the first text element into the layout. Clicking on it reveals all configuration and styling options. We provide our company data as static information.
Now to the trickier part - the text element with parameter content to dynamically address the recipient. We create one parameter name. To preview our design and simulate report generation as if using real data from an application we add some test data.
We are set - drag & drop another text element into the layout. We add some static salutation message and open the parameter list with the button next to the text input field. It already suggests the just created parameter name. We click it to apply it to the text element.
2. Align and style text elements
Now that we have our elements added to the layout it's time to arrange and style them according to our needs. Clicking one of the elements reveals the various styling options. Using the key in combination with a click we can select multiple elements at once from both within the layout and in the menu panel. By the way, this is not limited to text elements. If more than one element is selected we get styling options to apply to all elements at once as well as alignment options.
If you plan to apply the same style to several elements in your report design you might as well use a style template.
3. Use rich text
Instead of applying one style to a whole text element you may opt to switch to rich text in order to be able to assign different styles to a single text element. Let's take our company information and style it a bit differently.
Of course, also the rich text takes dynamic parameters. However, it's limited by not being able to evaluate them (see next step of this tutorial).
4. Perform a simple evaluation
You've already learned how to manage text elements and fill them with both static and dynamic data. However, there's an additional feature worth noting: the "Evaluate" option. When activated, it signifies that the content of the text field is evaluated. Let's say we want to go beyond a simple greeting and include a salutation based on the known gender of the recipient.
Therefore, we need to add a parameter gender to base our evaluations on. To keep it simple the parameter is of type text.
Now, let's go back to the text field. We activate the "Evaluate" option. This also means that our text field must be a valid Python statement to not throw an error when we try to run the report because static text cannot be evaluated.
We create a valid expression, addressing a "Mr." in case the gender equals to male, a "Mrs." in case it equals to female and keep the neutral salutation in case we don't get that information.
Best Practices
•When using a text element line breaks will be applied as entered
•If the width of the text element is insufficient, the text will be wrapped automatically
•Should the text surpass the element height, it will automatically enlarge and adjust other layout items accordingly to preserve the layout design
•Take a look at the user guide explaining the expression syntax to learn more about applying correct Python statements.