function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gaurish Gopal GoelGaurish Gopal Goel 

Header and Footer on Visualforce

I want to insert an image as a header in my PDF and some text as a footer. There are total 3 pages. I want these header and footers to be repeated on every page.

 

I have applied some CSS which I found on the internet but none of them worked for me. I need it urgent. Please help.

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi Gaurish,

 

This is so simple.  All you need to do is using <apex:include/> component in the vf page.Your 2 pages for having as Header as one page and Footer as another page.

 

Say for example, HeaderPage is one VF and FooterPage is another VF page. You need to create a new page as following, if you want header and footer.

 

Try the following,

 

<apex:page>

      ......

   <apex:include pageName="HeaderPage"/>

    ......

         //your body of the page here

   ........

   <apex:include pageName="FooterPage"/>

 

</apex:page>

 

 

The above example can be used to display the header and footer for another page. If you going to create a page for site, then you need to give the site url for the Headerpage/Footerpage you have included in the vf page.

 

 

Hope so this helps you...!

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

 

Gaurish Gopal GoelGaurish Gopal Goel

I have tried this solution but  I want repeatition of header and footer on every page.

 

Suppose I have a pageblock table which might contain any number of records. That table may occupy more than one page depending upon the data. So in my pdf I want header and footer on every page.

 

This solution will put header and footer only in the beginning and end of the pdf not on every page. Could you please look into it.

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi Gaurish,

 

In your scenario are you using more than one VF page?. If so, what are all the pages you need to do header and footer apply the <apex:include/> components in your pages.

 

 

Hope so this helps you...!

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

 

Gaurish Gopal GoelGaurish Gopal Goel

I am not using more than vf pages. I have only one vf page in which I am using a pageblocktable which may contain any number of records depending upon the data. So the PDF generated may have any number of pages. I want header and footer to be repeated on every page of my pdf.

sunny522sunny522
Hai Gopal,Use the following vf page code to solve ur problem
<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">kskbgs</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>
If not working please change version settings to 26 or 25
Gaurish Gopal GoelGaurish Gopal Goel

I know the link from where you have copied this code. This is not working. Ok no issues, I think I will work out something else. Thanks for replying.

sunny522sunny522
Hai Gopal,
I have done this in my dev account.Its working.If not working change version settings.It will work