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
jnegijnegi 

How to set Header and Footer in Visualforce email tamplate?

Hi All,

 

I am creating a visualforce page "renderAsPdf" and using custom component to render the body of the PDF. Since the body is rendering at run time so it might take 2 to 3 pages. Now my question is:

 

  • How can I show Header and Footer in each page of the pdf?
  • How can I show Footer at the bottom of the last page rather than middel of the page where the body ends.

Thanks in advance!

Navatar_DbSupNavatar_DbSup

Hi,

 

 

1. Upload the PDFDocumentStyle.css file to your static resources in Salesforce.com. Make sure the name matches the file name.

2. Create a new component and call it "PDFHeaderFooter".

3. Open the PDFHeaderFooter.txt file and copy its contents to the PDFHeaderFooter component you just created and save.

4. Create an new Visualforce page and call it "PDFDocument"

5. Open the PDFDocument.txt file and copy its contents to the PDFDocument page you just created as save.

6. Thats all it takes. You can test the page by modifying your Salesforce.com url by adding "/apex/PDFDocument" to the end of the ur that starts with ".salesforce.com/"

 

 

 

<!--

* Custom Visualforce Component that enables a PDF rendered Visualforce

* page to display repeating header and footers. This component supports

* displaying left, right, and center header text as well as page numbers.

-->

<apex:component >

 <!-- Component Attributes -->

 <apex:attribute type="string" name="type"

  description="Determines if the component renders as a header or footer" />

 <apex:attribute type="string" name="position"

  description="Determines if component should render the text on the left, center, or right" />

 <apex:attribute type="boolean" name="showPageNumbers"

  description="Determines if the header/footer information displays the page number information." />

 

 <!-- Component Variables -->

 <apex:variable var="styleClass" value="{!LOWER(type)}_{!LOWER(position)}"/>

 

 <!-- Component Body -->

 <apex:outputPanel id="panelHeaderFooter"

  styleClass="{!styleClass}"

  layout="block">

 

  <apex:outputPanel layout="none" rendered="{!showPageNumbers}">

   <div>Page <span class="pageNumber"/> of <span class="pageCount"/> </div>

  </apex:outputPanel>

 

  <apex:componentBody />

 </apex:outputPanel>

</apex:component>

 

 

<!--

* Sample Visualforce page that demonstrates how to use the PDFHeaderFooter component.

-->

 

<apex:page renderas="pdf">

 <!-- Stylesheets -->

 <apex:stylesheet value="{!$Resource.PDFDocumentStyle}" />

 

 <!-- First Page Header -->

 <c:PDFHeaderFooter type="header" position="left">

  <div style="padding: 10px; background-color: #ccc">Your Logo Here</div>

 </c:PDFHeaderFooter>

 <c:PDFHeaderFooter type="header" position="center">First Center Header Text</c:PDFHeaderFooter>

 <c:PDFHeaderFooter type="header" position="right">First Right Header Text</c:PDFHeaderFooter>

 

 <!-- All Pages Header -->

 <c:PDFHeaderFooter type="header" position="left">

  <div style="padding: 10px; background-color: #ccc">Your Logo Here</div>

 </c:PDFHeaderFooter>

 <c:PDFHeaderFooter type="header" position="center">Second Center Header Text</c:PDFHeaderFooter>

 <c:PDFHeaderFooter type="header" position="right">Second Right Header Text</c:PDFHeaderFooter>

 

 <!-- All Pages Footer -->

 <c:PDFHeaderFooter type="footer" position="left">First Left Footer Text</c:PDFHeaderFooter>

 <c:PDFHeaderFooter type="footer" position="center">First Center Footer Text</c:PDFHeaderFooter>

 <c:PDFHeaderFooter type="footer" position="right" showPageNumbers="true"/>

 

 <!-- Content -->

 <h1 style="padding-top: 3000px; background-color: #eee;">My Test Document</h1>

 <p>Test text</p>

 

 <!-- Last Page Footer -->

 <c:PDFHeaderFooter type="footer" position="left">Second Left Footer Text</c:PDFHeaderFooter>

 <c:PDFHeaderFooter type="footer" position="center">Second Center Footer Text</c:PDFHeaderFooter>

 <c:PDFHeaderFooter type="footer" position="right" showPageNumbers="true"/>

</apex:page>

 

for more help you can help from the following links.

http://www.iterativelogic.com/visualforce-pdf-repeating-headers-and-footers

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.