+ Start a Discussion
jbozajboza 

Formatissues to long text

I am passing a long text box that contains a copy of an email to a VF page that renders a PDF but the formatting is distorted. I want it to keep the format and stucture of the saved text in the comments box. This would look as the email was because this is my way of printint the email.

SaraagSaraag

You may have to replace  line characters with respective HTML tags. 

 

E.g: 

 

Inside controller:

LongTextField.replace('\n','<br/>')

 

In Apex Page,  to escape HTML:

<apex:outputtext escape="false" value="{!LongTextField}"></apex:outputtext>

 

Saraag

 

 

 

jbozajboza

That did nothing as here is my code and I left the way I did it and your suggestion.

 

Controller:

 

global with sharing class TaskController{

    public Task tsk{get;set;}
    public TaskController(){
        tsk=[select Description from Task limit 1];
        tsk.Description.replace('\n','<br/>');      
    }  
}

 

VF Page:

 

<apex:page controller="TaskController" showHeader="false" renderAs="PDF">
    <div align="center" width="550px">
        <h1>Current Email</h1>
    </div>   
    <div align="left" width="550px">
            <b>
        <apex:outputText value="{!tsk.Description}"/>
         <apex:outputtext escape="false" value="{!tsk.Description}"></apex:outputtext>
            </b>
           </div>
</apex:page>
            

SaraagSaraag

You're not storing back the value.        

tsk.Description=tsk.Description.replace('\n','<br/>');      

jbozajboza

That worked for formatting but if I try to pdf a second document after itwill still give me the last one. Is it storing the information. I need to be able to go to different accounts and chose to pdf this field.

SaraagSaraag

adding that code line will not actually save the value. I personally, wouldn't want to store the data replacing \n with <br/> into the field. Not sure I understand you question about second pdf... if you meant in your SOQL you would remove Limit 1 when actually implementing it; then you'll have to loop through each record and do the replace for each record. The values are not actually stored unless you use UPDATE statement. But since this is just for display I would go through the loop and do it for every record.

 

Saraag

jbozajboza

I am just trying to be able to pdf the comments for the task object. I want to be able to choose  a task and be able to pdf the comments that are actually the email. Once I do this once it will only give me that data even if I choose another task.

jbozajboza

Just want to do for the current record choosen and only that record.

SaraagSaraag

It might be because you're using the constructor to set values. It's hard to say what you're trying to do without looking the code. Can you post the complete code?

jbozajboza

public class TaskController{
    public Task tsk{get;set;}    

public TaskController(){        

tsk=[select Description from Task limit 1];

tsk.Description.replace('\n','<br/>');    

}

 

VF Page:

 

<apex:page controller="TaskController" showHeader="false" renderAs="PDF">    

<div align="center" width="550px">        

<h1>Current Email</h1>    

</div>      

<div align="left" width="550px">             <b>        

<apex:outputText value="{!tsk.Description}"/>         

<apex:outputtext escape="false" value="{!tsk.Description}"></apex:outputtext>             </b>           

</div>

</apex:page>

 

I am also using on java click from a custom button located on the task page code:

 

window.location = '/apex/printtask'

jbozajboza

The code is below and also located up in this thread

SaraagSaraag

The query looks to be the issue here. If you're using window.location to open a page without any parameters, then you're just getting some random Task from your query.

 

select Description from Task limit 1- All this says is get me one Task, doesn't say which one.

 

You need to pass Id parameters to your VF page from custom button e.g: window.location='/apex/printtask?id={!Task.Id}'

 

and in the controller:


public class TaskController{
public Task tsk{get;set;}
  public TaskController(){

 

  Id taskId=(Id)ApexPages.currentPage().getParameters().get('Id');  //check for invalid Ids

  tsk=[select Description from Task where id=:taskid];

  tsk.Description=tsk.Description.replace('\n','<br/>');    

 

   }
}

 

Hope this helps

 

Saraag