Wednesday, 22 January 2014

visualforce page as pdf

We can deliver a visualforce page as pdf using renderAs attribute in page component of the visaulforce page. In the following example the page is rebdered as pdf that shows 10 account records in a table.

Visualforce page
-----------------
1
2
3
4
5
6
7
8
9
10
11
12
<apex:page controller="DemoPdfController" renderAs="pdf">
  <apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!accList}" var="rec">
           <apex:column value="{!rec.name}"/>
           <apex:column value="{!rec.annualrevenue}"/>
           <apex:column value="{!rec.type}"/>
           <apex:column value="{!rec.annualrevenue}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
  </apex:form>
</apex:page>
 
Controller
--------
1
2
3
4
5
6
public with sharing class DemoPdfController {
 Public List<account> accList{get;set;}
    Public DemoPdfController (){
     accList = [select id,name,type,accountnumber,annualrevenue from account  limit 10];
    }
}

No comments:

Post a Comment