+ Start a Discussion
nelnel 

VisualForce page renderAs pdf, how to add footer?

I'm using VisualForce page to generate pdf, has anyone successfully added footer to pdf?

 

I've tried the solution below by using @page stylesheet, but with no luck, the footer element is basically disappeared.

http://help.salesforce.com/apex/HTViewSolution?id=000003705&language=en_US

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sunny522sunny522
Hi nel,
use the following sample code.
public class testpdf1
{
public list<Account> opp{get;set;}
public testpdf1()
{
opp=[SELECT Name,Date_Time__c 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 donot get output,change version.
In visualforce page Go to version settings.
change salesforce api version to 26.0.

U will get output.
if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

All Answers

hitesh90hitesh90

Hi nel,

 

below is the sample example to add footer to renderAs pdf page.

 

Visualforce Page:

<apex:page renderAs="pdf">
    <html>   
    <head>
        <style>
            @page {
                @bottom-right {
                    content: "Your footer Message";
                }
            }
        </style>
    </head>
    <body style="border:1px solid black;" >
            testpage
    </body>
    </html>
</apex:page>

 

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/

sunny522sunny522
Hi nel,
use the following sample code.
public class testpdf1
{
public list<Account> opp{get;set;}
public testpdf1()
{
opp=[SELECT Name,Date_Time__c 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 donot get output,change version.
In visualforce page Go to version settings.
change salesforce api version to 26.0.

U will get output.
if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

This was selected as the best answer
Sindhu AmbarkarSindhu Ambarkar
Hi,
<body style="border:1px solid black;background-color:#236FBD;" >

          testpage
    </body>
Backgroundcolor and font family is not reflecting.Can you please check

Thanks & Regards,
Sindhu Ambarkar.