You need to sign in to do that
Don't have an account?
Replace <br /> with newline character while rendering PDF's
I am trying to render a PDF page using a text field value that currently has <br /> as part of the text field and still maintain the newlines breaks where the existing breaks exist. For example, I have a field named Other_Contact_Name__c with a value: My Name<br />3312 Hard Rock Court<br />Richmond, VA 23230
I want to render the field on a PDF so that the output apears as:
My Name
3312 Hard Rock Court
Richmond, VA 23230
I have tried this:
<apex:outputText value="{!SUBSTITUTE(Case.Other_contact_name__c,'<br />', '\r')}/>
I have also tried replacing with '\n', '\r\n' but the output simply is displaying whatever value I try to substitue. Any help would be greatly appreciated.
I'd expect the PDF renderer to handle <br/> components without any additional effort on your part.
I think you need to stop outputtext escaping the html, e.g.
All Answers
I'd expect the PDF renderer to handle <br/> components without any additional effort on your part.
I think you need to stop outputtext escaping the html, e.g.
Have you tried to use <apex:outputField> instead of <apex:outputText>. This will automatically add the linebreaks for you.
Thank you, that worked perfectly.
Hello bob buzzard,
I am now also facing the problem of Replace <br /> with newline character while rendering text files.
I am trying to render a text file using a text field value that currently has <br /> , as a result i got <br/> tag appear in the text file. could you pls help me with this???
Thank you in advance. :)
Best,
I think you'll have to find another way to do this - something that parses the field and removes any HTML tags. The problem is that if you specify the content type as text, then any HTML wouldn't be interpreted by the browser, as it is displaying everything as raw text.
Hello bob buzzard,
Big thank for your reply!!!
I am just new to saleforce so I would be very happy if you can share me some idear to aviod this problem. i just want to render data in text format but i don need <br/>tag appear in it the text.
I wonder if there are any apex code to solve this problem??? or in order to go new line, we can only use these tags \r, \n, <br/> ???
Thank you in adavance.
Best,
Is this in an HTML(Visualforce) page, or are you setting the content type of the page to text?
Hello bub,
I set the content type like this: contentType="application/csv#DomainList.csv;charset=utf8".
here is the sample of my code:
<apex:page standardController="Object__c" showHeader="false" sidebar="false" extensions="theController"
id="Thepage" contentType="application/csv#FileExport.csv;charset=utf8" cache="true" readOnly="true">
<apex:repeat value="{!FieldsList}" var="fields" id="theFieldsLoop1">"{!mapFieldLabel[fields]}",</apex:repeat>
<br/>
<apex:repeat value="{!AllRecords}" var="result" id="theDataLoop">
<apex:repeat value="{!FieldsList}" var="f" id="theFieldsLoop2">"{!result.mapDto[f]}",</apex:repeat>
<br/>
</apex:repeat>
</apex:page>
--------------------------
Thank you in advance for your reply :)
best,
And have you tried changing your merge fields to use outputtext with escape="false" ? E.g.
Hello bob,
I tried!!! but it dint work!! :( i still cannot solve it now.
Best,
So I guess you'll have to handle this server side, by replacing all instances of '<br/>' with '\n'.
You meant replace the html tag <br/> with "\n" in my code , right ???
Best,
I don't know. Do you add the HTML line breaks in via code? If so, then yes, replace it that way. If a user just types it in to a rich text area or similar, then no, you'll have to parse the string and replace it.
yes, i add it all in my apex page code.
I have no idear now. i did replace it to '\n' but it dint work.
my code sample:
--------------------------------
<apex:repeat value="{!FieldsList}" var="f" id="theFieldsLoop2">"{!result.mapDto[f]}",</apex:repeat>
\n
</apex:repeat>
---------------------------
Here is the sample of the result.
Name Age
\n"Marry" 20
\n"Jhon" 25
---------------
Best,
I guess that means that '\n' doesn't mean anything in CSV files. It sounds like you might have to actually move onto a new line. Not sure how you'd do that TBH.
What is TBH? Would mind clarifying a bit more clear about what just said?
Best, :)
TBH means to be honest.
Short answer, I don't know how you are going to be able to do it.
"move onto a new line" , it is what you think m not gonna be able to do it??? or the topic of my post???
However, i thank you very much for spend your time help me :)
You will be blessed ;)
I don't know how you are going to get a CSV file to throw a line break.
There must be ways to solve, or we can change to other solution beside csv file if it really does not work :)
Thank you again bob :)
Cheer :)
.
hi