function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DataData 

BR tags not rendering correctly in visualforce PDF.

I've created a PDF visualforce page for a purchase orders application i've created but when I pull out an address the address appears in the PDF as:

 

my house<br>My Address line 1<br>My address line 2<br>state<br>country<br>zipcode

 

and its not converting the <br> tags to new lines, how can I make it do that?

 

Thanks 

Best Answer chosen by Admin (Salesforce Developers) 
XactiumBenXactiumBen

You could use this in your pdf page so that Salesforce doesn't try escaping the tags (I assume that's the problem here):

 

<apex:outputText value="{!Purchase_Order__c.Ship_To_Address__c}" escape="false" />

 

Although be warned - if you try packaging this up Salesforce does tend to tell you to take escape="false" out when sending an app for security review.

 

 

I've also found that using this works as well for some reason that doesn't make sense to me:

 

 

<apex:page renderAs="pdf" ContentType="application/pdf">

{!Purchase_Order__c.Ship_To_Address__c} </apex:page>

 

All Answers

wesnoltewesnolte

Not sure if this works, but give it a go 

 

<p>my house</p>

<p>My Address line 1</p>

<p>My address line 2</p>

<p>state</p>

<p>country</p>

<p>zipcode</p>

<p>country</p>

<p>zipcode</p>

 

cheers,

Wes 

DataData

The problem is the address comes out from salesforce as one field:

 

{!Purchase_Order__c.Ship_To_Address__c}

 

 

wesnoltewesnolte

You have a few options.

 

1. Create an object Ship_To_Address__c with fields for each address line. Create a lookup relationship between this object and Purchase_Order__c.

2. Create multiple address fields in the Purchase_Order__c object e.g. Purchase_Order__c.ship_to_address_line1__c

3. Capture the address as the HTML with <br/> or <p>.

 

Cheers,

Wes 

XactiumBenXactiumBen

You could use this in your pdf page so that Salesforce doesn't try escaping the tags (I assume that's the problem here):

 

<apex:outputText value="{!Purchase_Order__c.Ship_To_Address__c}" escape="false" />

 

Although be warned - if you try packaging this up Salesforce does tend to tell you to take escape="false" out when sending an app for security review.

 

 

I've also found that using this works as well for some reason that doesn't make sense to me:

 

 

<apex:page renderAs="pdf" ContentType="application/pdf">

{!Purchase_Order__c.Ship_To_Address__c} </apex:page>

 

This was selected as the best answer
DataData

Brilliant thanks a lot. Strange about the ContentType...

 

DataData
I'm getting this issue with another field as well. This time its a text area field and someone has entered text with line breaks in it but these arn't translating through. I've tried both approaches for this but it doesn't work :( Any ideas? All the text just ends up on one line.
wesnoltewesnolte

Hey

 

When you say line breaks do you mean '\n'? Because these don't do anything. You'll have to use html markup.

 

Cheers,

Wes

DataData

yes and I need to a way to translate the \n to <br> in the pdf. Its an invoice where a line item could have a bit of a description for example a spec of a computer. So the sales rep has put in the text area for the product item:

 

1 x 1GB Dimm

2 x 500gb hard disk

3 x sound...

 

etc but it comes out on the PDF as:

 

1 x 1GB Dimm2 x 500gb hard disk3 x sound...

 

 

 

wesnoltewesnolte

try  <apex:inputTextArea richtext="true"/>. That might work. Otherwise you can use a Wysiwyg editor and that will output HTML for you.

 

Wes

DataData
Text area didn't work, but how do you use the wysiwyg editor? can't see it as a field type...
XactiumBenXactiumBen

You could try and use {!SUBSTITUTE(myField, '\n', '<br />')}

 

Not sure if it'll work though...

DataData
Nope substitute doesn't work.. you'd think there would be something... kinda fundamental.