I have a requirement to print email tasks as PDF. As standard printable view option will support on Task records, I have created a custom visualforce page with render as "PDF" as below:

<apex:page StandardController = "Task" renderAs="pdf">
    <apex:form >
    <apex:pageBlock >
        Subject: {!Task.Subject} <br/><br/>
        Sent Date: {!Task.Createddate}<br/><br/>
        From: {!Task.Owner.Email}<br/><br/>
        Email: {!Task.Description}

Now, I could able to successfully print the page but the text is coming unformatted. It is as follows:

Email: from: [email protected] Response for owner id Test On Tue, Mar 8, 2022 at 2:19 PM
Email output < wrote: > Lorem ipsum dolor sit amet> Lorem ipsum dolor sit amet > Lorem ipsum dolor sit amet > Lorem ipsum dolor sit amet > Lorem ipsum dolor sit amet > Lorem ipsum dolor sit amet

Is there anyway where we can print the above information as following


Also, can anyone suggest how to trim text till "wrote:" and only print the actual content.


  • Most of the SFDC formula language is supported in VF page - look at the text functions
    – cropredy
    Mar 11, 2022 at 18:44

1 Answer 1


The apex:pageBlock is causing the problem. It's not meant to have anything inside of it besides apex:pageBlockSection, apex:pageBlockButtons, and apex:pageBlockTable. Also, to make sure line breaks are preserved, you'll need some CSS.

Here's a close approximation of what you're looking to do:

<apex:page StandardController="Task" renderAs="pdf">
          <apex:outputText value="Subject" />
          <apex:outputText value="{!Task.Subject}" />
          <apex:outputText value="Date" />
          <apex:outputText value="{!Task.Createddate}" />
          <apex:outputText value="From" />
          <apex:outputText value="{!Task.Owner.Email}" />
          <apex:outputText value="Email" />
            style="white-space: pre-line"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .