How to give header and footer in pdf generation?
Sample code is given below.
Apex code:
public class testpdf1
{
public list<Account> opp{get;set;}
public testpdf1()
{
opp=[SELECT Name from Account limit 50];
}
}
Visualforce page:
<apex:page renderAs="pdf" Controller="testpdf1">
<head>
<style type="text/css" media="print">
@page {
size: 8.5in 11in;/* width height */
}
@page {
@top-center {
content: element(header);
}
@bottom-left {
content: element(footer);
}
}
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 align="right">Header</div>
</div>
<div class="footer">
<div>Page <span class="pagenumber"/> of <span class="pagecount"/></div>
</div>
<div class="content">
<p><apex:repeat value="{!opp}" var="item">
<tr>
<td class="tableContent">{!item.Name}</td>
</tr>
</apex:repeat></p>
</div>
</apex:page>
Note:If u are not able to get output please change version .
In visualforce go to:Version settings
change salesforce Api version to 26.0
Sample code is given below.
Apex code:
public class testpdf1
{
public list<Account> opp{get;set;}
public testpdf1()
{
opp=[SELECT Name from Account limit 50];
}
}
Visualforce page:
<apex:page renderAs="pdf" Controller="testpdf1">
<head>
<style type="text/css" media="print">
@page {
size: 8.5in 11in;/* width height */
}
@page {
@top-center {
content: element(header);
}
@bottom-left {
content: element(footer);
}
}
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 align="right">Header</div>
</div>
<div class="footer">
<div>Page <span class="pagenumber"/> of <span class="pagecount"/></div>
</div>
<div class="content">
<p><apex:repeat value="{!opp}" var="item">
<tr>
<td class="tableContent">{!item.Name}</td>
</tr>
</apex:repeat></p>
</div>
</apex:page>
Note:If u are not able to get output please change version .
In visualforce go to:Version settings
change salesforce Api version to 26.0
thanks for the post it helped me..
ReplyDelete