5


I am having some difficulty trying to show a hierarchy within a PDF without some of the basic HTML formatting constructs. Below is an example of me trying to format the content using span tags.

I have also tried formatting the rows themselves by formatting the td tags but, it causes the PDF to fail due to the markup being invalid. So, I am running out of normal approaches to this problem. If anyone has found a solution to this is, it would be most appreciated.

Added Information

Here is the Apex class that produces the list of Strings to be printed out.

The Apex Code

this.AccountDisplay = new List>();
this.AccountHeaders = new List();

for(PresenterNode SingleNode : this.Presenters[2].PresentationNodes) { SingleNode.DisplayFields[0] = '' + SingleNode.DisplayFields[0] + ''; this.AccountDisplay.add(SingleNode.DisplayFields); }

this.AccountHeaders = this.Presenters[2].DisplayFields;

This is how it is printed out via VisualForce

The VisualForce Code

   <table width='100%' border="1" cellpadding="10" cellspacing="0"> 
           <tr>
               <apex:repeat value="{!AccountHeaders}" var="AccountHeader">
                   <th>
                       {!AccountHeader}
                   </th>
               </apex:repeat>
</tr> <apex:repeat value="{!AccountDisplay}" var="AccountInfo"> <tr> <apex:repeat value="{!AccountInfo}" var="AccountField"> <td> {!AccountField} <td> </apex:repeat> </tr> </apex:repeat>
</table>

Like I commented before @mast0r, I believe I will have to find a way to link the style to the field and do something like this.

Probable Answer Done in VisualForce Side

<span style="margin-left: "{LinkedMarginValue|StyleString}"> {!AccountField} </span>

I just can't seem to find a decent way to do that without having jacked up VisualForce code.

3
  • 3
    Can you post your visualforce markup that's generating this output? Commented Aug 5, 2013 at 21:51
  • 2
    Most likely adding an escape=false or similar attribute to the right Visualforce component will allow you to define the left margin via Apex. As per @ca_peterson's comment, it is hard to be specific without the markup that is generating the page. Commented Aug 5, 2013 at 22:03
  • That worked Daniel! Commented Aug 6, 2013 at 15:57

2 Answers 2

2

The answer was the following changes:

Apex Code

         this.AccountDisplay = new List>();
         this.AccountHeaders = new List();

        for(PresenterNode SingleNode : this.Presenters[2].PresentationNodes)
        {
            Integer CellNumber = 0;
            List<String> Fields = new List<String>();
            for(String Field : SingleNode.DisplayFields)
            {
                if(CellNumber == 0)
                    Fields.add('<span style="margin-left: ' + 
                        ((AccountHierarchyPresenter.HierarchyNode)SingleNode).ChildOfNumber * 25 +
                        'px">' + SingleNode.DisplayFields[CellNumber] + '</span>');
                else
                    Fields.add('<span>' + SingleNode.DisplayFields[CellNumber] + '</span>');
                CellNumber++;
            }
            this.AccountDisplay.add(Fields);
        }

I am adding to those fields later if needed. Then under Daniel's suggestion, in the table, I just output my fields with the following:

VisualForce

<apex:outputText value="{!AccountField}" escape="false"/>

1

You can output text with apex:outputText tag and format it with style attribute:

<apex:page showheader="false" sidebar="false" renderAs="pdf" 
           controller="test1" standardStylesheets="true">

    <table border="0" margin="0" padding="2">
        <tr>
            <td><span style="color:red;">1.</span></td>
            <td><apex:outputText value="{!testacc.Name}"
                                 style="margin-left:10px;"/>
            </td>
        </tr>
        <tr>
            <td><span style="color:green;">2.</span></td>
            <td><apex:outputText value="{!testacc.street__c}"
                                 style="font-weight:bold;"/>
            </td>
        </tr>
    </table>

</apex:page>

The result looks like this:

enter image description here

3
  • It is close to what I need. I am simply printing out the style in the wrong place - from Apex. Apparently, it is only recognized as plain text when I read it out. So, I have to find a way to link a style tag to only specified cells in the table (any specified row and the first row in the column. Commented Aug 6, 2013 at 15:08
  • @ProgrammableMedley You need to use the inline css then. Commented Aug 6, 2013 at 15:49
  • 1
    I got it. I didn't realize you had to set the escape value to false. Once I did that, the span tags worked like they should have. Commented Aug 6, 2013 at 16:06

You must log in to answer this question.

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