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
pbattissonpbattisson 

outputText not rendering when displayed as PDF but fine in normal page

I have a page which is being rendered as a PDF that cause the values of certain outputExt field to not be displayed. These were initially ones where I had bound to a related object. I firstly tried to change them to display the name of the related object by retrieving this information in a SOQL query however this seemed not to work so I changed it to use just simple strings.

 

 

An example field on my VF PDF page is 

 

<apex:outputText label="Cause of Injury" escape="false" value="{!cause}" />
hello -> {!cause} - here

I have added the text below to try and locate the information on the page to see if the value was being returned. If I remove the renderAs ="pdf" part of the page then all the information displays as required. It is only when I am rendering as a pdf that this fails to work. 

 

Any ideas?

 

Thanks

 

Paul

Sangram Kesari RaySangram Kesari Ray
I'm not sure if this is relevant now, but i have faced a similiar issue. So i used Dynamic Visualforce Component and pushed html into outputText. Here's a sample code for generating a table out of outputText.
<apex:page standardController="CustomObj__c" 
           extensions="CustoCtrlExtn" 
           showHeader="false" 
           standardStylesheets="false" 
           sidebar="false" 
           applyHtmlTag="false" 
           applyBodyTag="false" 
           docType="html-5.0"
           renderAs="pdf">    
        
    <head>
    </head>    
    
    <body>    
        <apex:dynamicComponent componentValue="{!dynamicDetail}" />
    </body>    
</apex:page>

This'll be your method inside the extension.
public Component.Apex.PageBlock getDynamicDetail() {
    Component.Apex.PageBlock dynPageBlock = new Component.Apex.PageBlock();
    Component.Apex.OutputText oppText = new Component.Apex.OutputText(escape = false);

    oppText.value =  '<div class="some-css-class">--Title--</div>';
    
    oppText.value += '<div class="some-css-class">';
    oppText.value +=     '<div>';
    oppText.value +=         '<table class="some-css-class">';
    oppText.value +=             '<tr>';
    oppText.value +=                 '<td class="some-css-class" >--col1--</td>';
    oppText.value +=                 '<td class="some-css-class">--col2--</td>';
    oppText.value +=                 '<td class="some-css-class">--col3--</td>';
    oppText.value +=                 '<td class="some-css-class">--col4--</td>';
    oppText.value +=             '</tr>';

    //poplate the data dynamically
    for (List < String > item: someList) {

        oppText.value +=         '<tr>';
        oppText.value +=             '<td>' + item.get(0) + '</td>';
        oppText.value +=             '<td>' + item.get(1) + '</td>';
        oppText.value +=             '<td>' + item.get(2) + '</td>';
        oppText.value +=             '<td>' + item.get(3) + '</td>';
        oppText.value +=         '</tr>';
    }
    
    oppText.value +=         '</table>';
    oppText.value +=     '</div>';
    oppText.value += '</div>';

    dynPageBlock.childComponents.add(oppText);
    
    return dynPageBlock;
}

Hope it helps for generating views and renderering them as pdf as once view logic is put into controller, which is not recommeneded but opens up possibilities to deal with complex edge cases when there might not be any other way as due to renderAs="pdf", Javascript takes a backseat.