Formatting in Text - Printouts

When generating reports, any formatting done by the user is not coming in the reports in the case of TextAreas.

For Example, a user has entered the data in the Text field as -

Hello World !
This is Prakhar

The PDF file generated displays it as -

Hello World ! This is Prakhar

The code written in the FODT file is -


and uses the placeholder > text field in libre office.

This is a missing feature: Issue 2068: Allow to include richtext content in report - Tryton issue tracker

When you use e.g note = fields.Text('Note') you can split the content of that field based on the newline \n in your (f)odt report like

<for each="line in record.note.split('\n')">

Any richtext content like bold or italic or any other markup is ignored, but you get at least the whitespaces and white lines.

1 Like

@edbo When I used your solution, I got stuck in a new situation.

I wrote the following code -

<for each="line in qn.answer.split('\n')">

Scenario 1 - If the qn.answer is coming as None, then the system throws an error saying that None has no method as split.

Scenario 2 - I changed the code to the following -

<if test="qn.answer"><for each="line in qn.answer.split('\n')">

Now it says that the pair is mismatched or “No common ancestor found for opening and closing tag”.

Thanks in advance.

This error means that there is some tag that is not properly closed. The code you posted here looks ok, maybe the issues is somewhere else.

You can use the following code:

<for each="line in (qn.answer or '').split('\n')">

In order to use an empty string when answer is None.

If you want to ensure that this field is set you you can set the required attribute of the field to True.

Hope it helps!

You can’t have the if statement and for loop in one sentence. You have to add the for loop on a new line:

<if test="qn.answer">
   <for each="line in qn.answer.split('\n')">

But the code from @pokoli is much nicer.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.