+ Start a Discussion
harshasfdcharshasfdc 

Generating pdf for static calculated values

Hi All,

 

I have a require ment i have to generate the pdf file after performing some calculations where we perform calculations for static values .i want to save this as a pdf after performing the operation is this possible .please help in this.

 

Thanks,

Harsha

Shiva Ramesh @ xcdhrShiva Ramesh @ xcdhr

Page:

<apex:page standardController="Payroll_Period__c" renderAs="pdf" cache="false" sidebar="false" showheader="false">

<html>
<head>

</head>
    
    <c:PayrollPeriodPdfComp />     
    
    </html>

</apex:page>

 Component:

<apex:component access="Global" Controller="PayrollPeriodPdfController">
    
    <apex:attribute name="payId" description="This stores Payroll Id." type="Id" required="false" assignTo="{!payId}"/>
    
    <body>
    <table class="grid" width="100%" border="0" cellpadding="0" cellspacing="10">
              <tr>
	          <td width="30%" align="center" style="font-family:Arial;font-size:18pt;">                		 
	              <b><apex:outputText value="Payroll Period"/></b>  
			  </td> 
	          </tr>
              
              <tr>
              <td width="30%" align="left" style="Arial;font-size:12pt;">
	   			  <apex:outputText value="Payroll Period Name :"/>
				  <apex:outputText value="{!payroll.Name}" Id="NameValue"/>
			  </td>
			  </tr>
			  <tr>
			  <td width="30%">  
				 <apex:outputText value="Employee Detail:"/>
	              <apex:outputText Id="EmployeeDetail2" value="{!payroll.Employee_Detail__r.name}"/>
	          </td> 
	          </tr>
	 </table>
	 
	 <table class="grid" width="100%" border="0" cellpadding="0" cellspacing="20">          
	          <tr>
	          <td width="30%" align="left" style="font-family:Arial;font-size:12pt;">                		 
	              <apex:outputText value="Salary :"/>
	              <apex:outputText id="Salary2" value="{!payroll.Salary__c}" /> 
	          </td> 
	          <td width="10%">
				  &nbsp;          
			  </td>
	          <td width="30%" align="left" style="font-family:Arial;font-size:12pt;">                		
	              <apex:outputText value="Wages :"/>
	              <apex:outputText Id="Wages2" value="{!payroll.Wages__c}" /> 
	          </td> 
	          </tr>
	          
	          <tr>
	          <td width="30%" align="left" style="font-family:Arial;font-size:12pt;">
	              <apex:outputText value="Additions :"/>
	              <apex:outputText Id="Additions2" value="{!payroll.Additions__c}" /> 
	          </td> 
	          <td width="10%">
				  &nbsp;          
			  </td>
	          <td width="30%" align="left" style="font-family:Arial;font-size:12pt;">                		
	              <apex:outputText value="Allowance :"/>
	              <apex:outputText Id="Allowance2" value="{!payroll.Allowance__c}" /> 
	          </td> 
	          </tr>
	         	              
	          <tr>
	          <td width="30%" align="left" style="font-family:Arial;font-size:12pt;">                		
	              <apex:outputText value="Commission :"/>
	              <apex:outputText Id="Commission2" value="{!payroll.Commission__c}" /> 
	          </td> 
	          <td width="10%">
				  &nbsp;          
			  </td>
	          <td width="30%" align="left" style="font-family:Arial;font-size:12pt;">                		
	              <apex:outputText value="Deduction :"/>
	              <apex:outputText Id="FixedDeduction2" value="{!payroll.Fixed_Deduction__c}" /> 
	          </td> 
	          </tr>
	          	          
	          <tr>
	          <td width="30%" align="left" style="font-family:Arial;font-size:12pt;">                		
	              <apex:outputText value="Gross Pay :"/> 
	              <apex:outputText Id="Gross2" value="{!payroll.Gross_Pay__c}"/> 
	          </td> 
	          </tr>
	     </table>       
    </body>
</apex:component>

 Controller:

public with sharing class PayrollPeriodPdfController{
    public Payroll_Period__c payroll{get;set;}
    public Id payId {get;set;}
    
    public PayrollPeriodPdfController(){
    	
payId = ApexPages.currentPage().getParameters().get('Id');
    	payroll =[select id,Name, Additions__c, Allowance__c, Benefits__c, Bonus__c, Commission__c,Employee_Detail__c, Employee_Detail__r.name, Fixed_Deduction__c, Gross_Pay__c, Notes__c, Overtime__c, Salary__c, Wages__c from Payroll_Period__c where id =: payId];
    
    }  
   
}

 the generate PDF link call the page like this in your VF page:

<table align="right">
<tr>
<td style="color:Black;text-align:center;font-size:8pt;">
<apex:commandLink action="{!PayrollPeriodPdf}" value="Generate PDF" target="_top">
<apex:param name="payId" value="{!payroll.id}" assignTo="{!selPeriod}"/> 
</apex:commandLink>
</td>
</tr>
</table>

 In your controller:

public PageReference PayrollPeriodPdf(){
        
        PageReference p = page.PayrollPeriodPdf;
        p.getParameters().put('id',payroll.Id);
        
        p.setRedirect(true);
        return p;
        }

 

Shiva Ramesh @ xcdhrShiva Ramesh @ xcdhr

ya we can do that without object creation. By using {get;set;} property we can get the values from VF page to controller and save it as a record. from that we can also fetch the data to generate PDF.

these links will helps you:

Getter and setter methods are used to pass data from your visualforce page to your controller and vice versa..

http://www.forcetree.com/2009/07/getter-and-setter-methods-what-are-they.html


http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_custom_settings.htm

 

http://www.salesforce.com/docs/developer/cookbook/Content/apex_properties.htm

 

http://blog.jeffdouglas.com/2010/07/16/create-and-email-a-pdf-with-salesforce-com/