problem with newline in report

I’m having problems with newline characters not being recognized in reports. Specifically, I am using reporting with docx as both input and output format. When a TextArea field is printed, any newline characters - which display fine on screen - are removed. The text just runs together in a big long line, evidently with no “\n” or “\r\n”.

Is there a way to fix this? Is Cuba handling these correctly?

Thanks
Eric

2 Likes

Just to clarify… when I print a String property that was edited with a TextArea component, the report removes all the linefeeds. Persistence and screen display work fine. Same problem on Windows and OSX.

Anyone else having problems with this? Workaround?

Thanks
Eric

Hi Eric,
I have tried to reproduce the problem but in my report lines are printed ok.
Could you share the report? You can get the report using the “Export” button on the Reports -> Reports screen.

Thanks for the reply. Here it is…

Visit Report.zip (44.8K)

Hi,
I have looked at your report and created a similar one.
Still could not reproduce the problem: new line is correctly printed on a new line.
I use the platform version 6.5.5 in my test project. Which version do you use?
Does the issue occur with both templates? Which fields should have multiple lines?

The hpi and plan fields should allow multiple lines. And, I’m using 6.5.5. Not quite sure what you mean by “both templates”??

Thanks for trying to help with this. I’ll keep looking on my end.

Eric

I have the same issue. The column has text type (unlimited string) and in the docx the output doesn’t print the new lines.
I have used plain SQL to retrieve data, not groovy script.

Because I didn’t find a solution (don’t know if it’s a bug or not) I have found a workaround (quite ugly though).
Instead of normal field I used inline html in the docx report as described here: https://github.com/cuba-platform/yarg/wiki/Quick-start
and so the actual field is actually replaced with a html which I built dynamically and includes
tag.
For this I created a function in groovy wich splits the string by the newline character:


def makeHTML(String val) {

    def htmlpre = '<html><body><h3 style="font-family:arial; font-weight:normal; font-size:16px">'
    def htmlsuf = '</h3></body></html>'

    if (val == null) {
        return htmlpre+htmlsuf
    }
    def cReturn = htmlpre
    def valLines = val.split("\\r?\\n")
    for(valLine in valLines){
        cReturn += valLine + "<br>"
    }

    cReturn += htmlsuf
    return cReturn
}

I am having a similar problem, new line is being identified as a space.

Thanks for this workaround,

I am not quite sure how to add this groovy script with my SQL queries which return a string with possible new lines, would you mind explaining it in a more detailed way?

Thanks in advance

I face the same problem. Input is DOCX and output is PDF (generated via libreoffice 6.4)

Entity field:

    @Lob
    @Column(name = "FOOTER_TEXT")
    var footerText: String? = null

No newlines are printed in the report. Newline character is converted to space.

Input (content of database field):

... footer test...
newline

next

Output in PDF:
image

Hi. The problem only occurs when the output is set to PDF. I found a workaround - add 2 space characters at the end of line, prior to the line break. That way the PDF renders properly with line feeds.
It also depends on the font and its size. Times New Roman, size 10 shows everything on a single line, while size 12 works fine. So it is font-specific…
On a second thought… I lost more than an hour playing with cell width, font name/size and db field content - the 2 spaces workaround stopped working as long as the text fit in 1 cell, so I had to remove cell merge and set cell width short enough to trigger multi line split…
Nah… it’s a PDF mess. I give up.

It has nothing to do with the PDF output actually… Also, when you generate a report from DOCX to DOCX the newlines are also removed…

The newline character is converted into a space character.

1 Like

I endeed up splitting my multiline text to 3 fixed lines, and putting them into 3 separate placeholder fields.

Yes, I tried that too, but this looks ugly on my report when I don’t have multiple lines, because then there is a space that is not needed.

Ok, I got it working by implementing my own DocxFormatter (actually extending from the existing) and replacing a new line token with </w:t><w:br/><w:t> in the MainDocumentPart.

Maybe I should build a pull request.

1 Like

@klaus Could you please show how that has to be done?

@pakogeza See my pull request: https://github.com/cuba-platform/yarg/pull/144

@klaus Thanks, really appreciated!