I am adding a custom object to pdf template, but a...
# ask-stanley-ai
x
I am adding a custom object to pdf template, but address field style for line break is not working properly var renderer = render.create(); renderer.setTemplateByScriptId('CUSTTMPL_240_7311791_254'); renderer.addRecord("record", recordObj); renderer.addCustomDataSource({ format: render.DataSource.OBJECT, alias: 'jsonData', data: jsonPDFData }); var newfile = renderer.renderAsPdf(); The above jsonPDFData has such information {"mainaddress_text":"NEW PORT PACIFIC LIMITED\r\nUnit B 17/F United Centre\r\n95 Queensway Admiralty \r\nHong Kong"} when pdf is rendered, it's showing like the following (i've tried to replace "\r\n" with "<br/>") NEW PORT PACIFIC LIMITED <br/>Unit B 17/F United Centre <br/>95 Queensway Admiralty <br/>Hong Kong Please advise me any suitable solution to resolve this issue
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems like you are trying to add line breaks to an address field in a PDF template. The issue you are facing is that the line breaks are not being rendered correctly and instead, they are being displayed as
<br/>
in the output. One solution to this problem is to replace the newline characters (
\r\n
) with a unique character in your data source, and then replace that unique character with
<br/>
in your PDF template. Here's how you can do it: 1. In your data source, replace the newline characters with a unique character. For example, you can use the pipe character (
|
):
Copy code
javascript
var jsonPDFData = {
  "mainaddress_text": "NEW PORT PACIFIC LIMITED\r\nUnit B 17/F United Centre\r\n95 Queensway Admiralty \r\nHong Kong"
};
jsonPDFData.mainaddress_text = jsonPDFData.mainaddress_text.replace(/\r\n/g, '|');
2. In your PDF template, replace the unique character with `<br/>`:
Copy code
html
${jsonData.mainaddress_text?replace("|", "<br/>")}
This way, the line breaks should be rendered correctly in your PDF. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.844820082
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.842774391
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.837997615
Please provide your feedback on this answer.