Example:
Apex Class :
public class GeneratePdf {
public List<Account> accList {get;set;}
public void generateReport() {
accList = [select id,name,AccountSource,phone,industry from Account];
}
}
Visualforce Page :
<apex:page renderAs="pdf" applyBodyTag="false" controller="GeneratePdf" action="{!generateReport}" applyHtmlTag="false" showHeader="false">
<head>
<style type="text/css" media="print">
@page {
@top-center {
content: element(header);
}
@bottom-left {
content: element(footer);
}
margin-top: 100px;
margin-bottom:80px;
}
div.header {
padding: 10px;
position: running(header);
}
div.footer {
display: block;
padding: 5px;
position: running(footer);
}
.pagenumber:before {
content: counter(page);
}
.pagecount:before {
content: counter(pages);
}
</style>
</head>
<div class="header">
<div><center>List Of Accounts</center></div>
</div>
<div class="footer">
<div>Page <span class="pagenumber"/> of <span class="pagecount"/></div>
</div>
<div class="content">
<table cellspacing="0" cellpadding="5" width="100%" style="line-height:25px" border="1">
<tr width="100%" style="border:1px">
<th>Account Name</th>
<th>AccountSource</th>
<th>Industry</th>
<th>Phone</th>
</tr>
<apex:repeat value="{!accList}" var="acc">
<tr width="100%" style="border:1px solid">
<td>{!acc.name}</td>
<td>{!acc.AccountSource} </td>
<td>{!acc.Industry} </td>
<td>{!acc.phone} </td>
</tr>
</apex:repeat>
</table>
</div>
</apex:page>
Output:
Apex Class :
public class GeneratePdf {
public List<Account> accList {get;set;}
public void generateReport() {
accList = [select id,name,AccountSource,phone,industry from Account];
}
}
Visualforce Page :
<apex:page renderAs="pdf" applyBodyTag="false" controller="GeneratePdf" action="{!generateReport}" applyHtmlTag="false" showHeader="false">
<head>
<style type="text/css" media="print">
@page {
@top-center {
content: element(header);
}
@bottom-left {
content: element(footer);
}
margin-top: 100px;
margin-bottom:80px;
}
div.header {
padding: 10px;
position: running(header);
}
div.footer {
display: block;
padding: 5px;
position: running(footer);
}
.pagenumber:before {
content: counter(page);
}
.pagecount:before {
content: counter(pages);
}
</style>
</head>
<div class="header">
<div><center>List Of Accounts</center></div>
</div>
<div class="footer">
<div>Page <span class="pagenumber"/> of <span class="pagecount"/></div>
</div>
<div class="content">
<table cellspacing="0" cellpadding="5" width="100%" style="line-height:25px" border="1">
<tr width="100%" style="border:1px">
<th>Account Name</th>
<th>AccountSource</th>
<th>Industry</th>
<th>Phone</th>
</tr>
<apex:repeat value="{!accList}" var="acc">
<tr width="100%" style="border:1px solid">
<td>{!acc.name}</td>
<td>{!acc.AccountSource} </td>
<td>{!acc.Industry} </td>
<td>{!acc.phone} </td>
</tr>
</apex:repeat>
</table>
</div>
</apex:page>
Output:
No comments:
Post a Comment