Search code examples
pdfnetsuitesuitescriptsuitescript2.0

How to reflect TEXT AREA / LONG TEXT field values in formatted way in PDF suitelets


We have a suitlet which is creating PDF. In our NetSuite UI, there is a long text and a text area field, OBJECTIVE and DESCRIPTION, respectively. When the user puts some value in it, he includes some spaces and line breaks along with text, it does show in the UI, but not in PDF.

UI example:

enter image description here

But in our PDF it reflects like this:

enter image description here

Code Chunk:

                       strTable += '<table width="100%" table-layout="fixed" margin-top="30px">'
                            strTable += '<tr>'
                                strTable += '<td><b>Objective:</b></td>'
                            strTable += '</tr>'
                            strTable += '<tr height="110px">'
                                strTable += '<td style="background-color:#89AD81; color:white;"><p align="left">' + objective + '</p></td>'
                            strTable += '</tr>'
                            strTable += '<tr margin-top="30px">'
                                strTable += '<td><b>Description:</b></td>'
                            strTable += '</tr>'
                            strTable += '<tr height="210px">'
                                strTable += '<td style="background-color:#89AD81; color:white;"><p align="left">' + description + '</p></td>'
                            strTable += '</tr>'
                        strTable += '</table>'

Please Note: i tried using the RICH TEXT field and it was reflecting results as required but when the text is huge, it gets cut from the end of the page.


Solution

  • The issue is that newline characters are not represented as new lines in XML, which is what is generated for the BFO library to process into PDF. You could modify the content of the fields to hold XML (or XML compatible HTML - XHTML), but for your use case it might be enough to simply replace newline characters with XHTML break tags:

    objective.replace(/\n/g, '<br />')