Export Account Data as PDF using VF Page

In this article we will learn about generating PDF file using VF Page. Here I will generate PDF file using Account data instead of account you can use any other standard or custom object
first we will create APEX class with ExportAccountCtrl name

				
					public class ExportAccountCtrl {
    public List<Account> AccList {get; set;}
    public void getAccounts(){
        AccList = [SELECT Name, Type, Rating, Industry FROM Account];
    }
}
				
			

now we will create VF page with ExportPDF name

				
					<apex:page controller="ExportAccountCtrl" action="{!getAccounts}" applyBodyTag="false" showHeader="false" renderAs="pdf">
    <head>
        <style>
            @page {
            size: 4in 6in landscape;
            }
            table th {
            padding: 15px 5px;
            text-align: left;
            color: #000;
            }
            table, th, td {
            border: 1px solid black;
            border-collapse: collapse;
            }
        </style> 
    </head>
    <body>
        <table>
            <tr>
                <th>Account Name</th>
                <th>Type</th>
                <th>Rating</th>
                <th>Industry</th>
            </tr>
            <apex:repeat value="{!AccList}" var="acc">
                <tr>
                    <td>{!acc.Name}</td>
                    <td>{!acc.Type}</td>
                    <td>{!acc.Rating}</td>
                    <td>{!acc.Industry}</td>
                </tr>
            </apex:repeat>
        </table>
    </body>    
</apex:page>
				
			

Output

Leave a Comment