1

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}
        
    </apex:pageBlock>
  </apex:form>
</apex:page>

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

Foramtted

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

Thanks!

1
  • 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

2

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:form>
    <apex:pageBlock>
      <apex:pageBlockSection>
        <apex:pageBlockSectionItem>
          <apex:outputText value="Subject" />
          <apex:outputText value="{!Task.Subject}" />
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem>
          <apex:outputText value="Date" />
          <apex:outputText value="{!Task.Createddate}" />
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem>
          <apex:outputText value="From" />
          <apex:outputText value="{!Task.Owner.Email}" />
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem>
          <apex:outputText value="Email" />
          <apex:outputText
            value="{!Task.Description}"
            style="white-space: pre-line"
          />
        </apex:pageBlockSectionItem>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

You must log in to answer this question.

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