+ Start a Discussion
Carter85Carter85 

Render as PDF Question

When rendering as a PDF can I not display a dynamic grand total footer calculation in a table?
In my page I have a section like this:
<apex:pageBlock >
		  <apex:pageBlockSection title="Tire and Wheel Contracts" rendered="{!NOT(ISNULL(tcontractList))}">
          <apex:variable value="{!0.00}" var="total1"/>
          <apex:pageBlockTable value="{!tcontractList}" style="border:1px solid black;" var="c" rendered="{!NOT(ISNULL(tcontractList))}">
          <apex:column style="border:1px solid black; text-align:center; width:85px; font-weight:bold; color:blue;" id="note" value="{!c.rContract.Contract_Number__c}" headerValue="Contract #"/>
          <apex:column style="border:1px solid black; text-align:center; width:95px" value="{!c.rContract.Vin_Number__c}" headerValue="VIN"/>
          <apex:column style="border:1px solid black; text-align:center; width:125px" value="{!c.rContract.Name}" headerValue="Name"/>
          <apex:column style="border:1px solid black; text-align:center; width:125px; font-weight:bold; color:blue" value="{!c.rContract.Policy_Type__c}" headerValue="Policy Type"/>
          <apex:column style="border:1px solid black; text-align:center; width:95px" value="{!c.rContract.Term__c}" headerValue="Term"/>
          <apex:column style="border:1px solid black; text-align:center; width:95px" value="{!c.rContract.Class__c}" headerValue="Class"/>
          <apex:column style="border:1px solid black; text-align:center; width:95px" value="{!c.rContract.Benefits_Options__c}" headerValue="Option"/>
          <apex:column style="border:1px solid black; text-align:center; width:95px" value="{!c.rContract.Effective_Date__c}" headerValue="Purchase Date"/>
          <apex:column style="border:1px solid black; text-align:center; width:95px" headerValue="Dealer Cost">
          <apex:outputField value="{!c.rContract.Dealer_Cost__c}" />
          <apex:variable var="total1" value="tdueAmount" />
           	<apex:facet name="footer">
            	<span style="font-weight:bold; color:blue">Total Due: $<span class="t1"></span></span>
          	</apex:facet>
          </apex:column>
		  </apex:pageBlockTable>
          <br/>
          <script>
    			// Here we will set the generated subtotals to the footer cells
    			document.getElementsByClassName('t1')[0].innerHTML = '{!total1}';
    	  </script>
          </apex:pageBlockSection>
And the only thing which does not display is the total calculation in the footer.  I know it's operating correctly because I have this same code on the referring page where the user can then choose to create the PDF to print off which opens this new page where the figure does not show up.  Is there some sort of restriction in the renderAs PDF option which prevents this from working properly, or is there an allowance I need to make in this situation to make sure it does show up?
 
Best Answer chosen by Carter85
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Carter85:

  I have a small recommendation for you! 

 I assume "tcontractList" is a wrapper class to which you were adding values (rContract is one of the property of the wrapper class). Create a Decimal varibale in Contoller called "TotalValue" which will be calculated on the controller side while you add the records to the tcontractlist wrapper class.

for eg.,
 
Public demical TotalDealerCost{get;set;}

Some method/get method of your tcontractList var:


Public List<CONTRACTWRAPPER> gettcontractList{

TotalDealerCost=0.0;

for(Contract c: ListOfcontracts){ // loop where you add records to the loop

//adding contracts to the wrapper class

if(c.Dealer_Cost__c!=Null && c.Dealer_Cost__c>0)
TotalContractvalue+=Dealer_Cost__c;
}//By end of this loop you will have the total dealer cost calculated

}



Now on vf page in the footer:
<apex:column style="border:1px solid black; text-align:center; width:95px" headerValue="Dealer Cost">

          <apex:outputField value="{!c.rContract.Dealer_Cost__c}" />

          
            <apex:facet name="footer">

                <span style="font-weight:bold; color:blue">Total Due: $ {!TotalDealerCost}</span>

            </apex:facet>

          </apex:column>


Hope it works for you!

Thanks,
Balaji

All Answers

Balaji Chowdary GarapatiBalaji Chowdary Garapati

@Carter85:

In the below document :
https://www.salesforce.com/us/developer/docs/pages/Content/pages_output_pdf_considerations.htm

It says "PDF rendering doesn’t support JavaScript-rendered content.", which i assume what the script is doing ! 

I have a small question for you:
why dont you use the {!Total1} directly between the span tags, instead of adding through script? - Just asking as i dont see you were adding anything dynamically to the Total value in the script itsself!


Thanks,
Balaji

Carter85Carter85
Well I was using the script because that was the only way I could get it to render for some reason, every other way I tried it wouldn't display at all.  If you have a better suggestion I'm definitely open.  For the pdf render then would you have any suggestions how to easily transfer that over from the referring page?  I'm trying to avoid passing parameters if I can help it as there could potentially be at least 15 separate tables which would need to be displayed (not likely, but I have to account for it).
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Carter85:

  I have a small recommendation for you! 

 I assume "tcontractList" is a wrapper class to which you were adding values (rContract is one of the property of the wrapper class). Create a Decimal varibale in Contoller called "TotalValue" which will be calculated on the controller side while you add the records to the tcontractlist wrapper class.

for eg.,
 
Public demical TotalDealerCost{get;set;}

Some method/get method of your tcontractList var:


Public List<CONTRACTWRAPPER> gettcontractList{

TotalDealerCost=0.0;

for(Contract c: ListOfcontracts){ // loop where you add records to the loop

//adding contracts to the wrapper class

if(c.Dealer_Cost__c!=Null && c.Dealer_Cost__c>0)
TotalContractvalue+=Dealer_Cost__c;
}//By end of this loop you will have the total dealer cost calculated

}



Now on vf page in the footer:
<apex:column style="border:1px solid black; text-align:center; width:95px" headerValue="Dealer Cost">

          <apex:outputField value="{!c.rContract.Dealer_Cost__c}" />

          
            <apex:facet name="footer">

                <span style="font-weight:bold; color:blue">Total Due: $ {!TotalDealerCost}</span>

            </apex:facet>

          </apex:column>


Hope it works for you!

Thanks,
Balaji
This was selected as the best answer
Balaji Chowdary GarapatiBalaji Chowdary Garapati
Sorry one more thing! im suggesting to use controller code instead of script is for this reason:

http://www.salesforce.com/docs/developer/pages/Content/pages_compref_variable.htm

In the above link it says apex varaible can not be incremented in an iteration, and that is the reason why you might not be able to render it on page unless you use script and force it to appear :), which is breaking in case of PDF.

Thanks,
Balaji
Carter85Carter85
That helped resolve it, thanks.