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
hramanihramani 

VF render as PDF affecting my text area field’s line breaks

I have a VF page pulling a field set and displaying the data from the fields present in the field set.
In the below code the field set ‘Essay_Cover_Sheet’ contains a text area field named ‘Essay_Body__c’. Essay_Body__c has data with line breaks.
When the VF renders as PDF , I don’t see the line breaks, it directly appears as a single paragraphs.

I want the text area fields to appear on the VF pdf, as it appears on the record detail page with line breaks.


<apex:page standardController="TargetX_SRMb__Essay__c" showHeader="false" applyHtmlTag="false" applyBodyTag="false" standardStylesheets="false" renderAs="PDF">
    <head>
        <style type="text/css">
            @page {
                margin-top: 100px;
                margin-bottom: 100px;
            }
        </style>
    </head>
    <body>
        <div>
            <h2>Essay</h2>
            <table width="100%" cellpadding="5px" cellspacing="5px">
                <tbody>
                    <apex:repeat value="{!$ObjectType.TargetX_SRMb__Essay__c.FieldSets.Essay_Cover_Sheet}" var="field">
                        <tr>
                            <td><b>{!field.label}</b></td>
                        </tr>
                        <tr>
                            <td>{!TargetX_SRMb__Essay__c[field.fieldPath]}</td>
                        </tr>
                    </apex:repeat>
                </tbody>
            </table>
        </div>
    </body>
</apex:page>



 
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

A Visualforce page rendered as a PDF file displays either in the browser or is downloaded, depending on the browser’s settings. Specific behavior depends on the browser, version, and user settings, and is outside the control of Visualforce.

You can use HTML Tag <pre>. This will ensure line breaks are respected. You can also set escape="false" property with apex:outputText

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas