How to make header and footer fixed and repeat on Visualforce page rendered as PDF in Salesforce | How to add header and footer in Visualforce page rendered as PDF in Salesforce

1,395 views

Hey guys, today in this post we are going to learn about How to make header and footer fixed and repeat on Visualforce page rendered as PDF in Salesforce.

A Visualforce page rendered as a PDF file displays either in the browser or is downloaded, depending on the browser’s settings. Specific behavior depends on the browser, version, and user settings, and is outside the control of Visualforce. To know more details, Click Here.

 

 

Final Output →

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!

 

header and footer fixed and repeat on visualforce page -- w3web.net

 

You can download file directly from github by Click Here.

 

Other related post that would you like to learn in Salesforce

 

  • Find the below steps ▾

 

Create Visualforce Page

Step 1:- Create Visualforce Page : pdfHeaderFooterFixedVf.vfp

From Developer Console >> File >> New >> Visualforce Page

pdfHeaderFooterFixedVf.vfp [Visualforce Page]

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 
  1.   <apex:page renderAs="pdf" applyHtmlTag="false" showHeader="false"  title="Quotation PDF" standardStylesheets="false"
  2.            applyBodyTag="false" showQuickActionVfHeader="false">
  3.     <html>
  4.         <head>
  5.             <style>
  6.                 @page {
  7.                 size: A4;
  8.                 margin-top: 4.0cm;
  9.                 margin-bottom: 2.6cm;
  10.                 margin-left: 0.3cm;
  11.                 margin-right: 0.3cm;
  12.  
  13.                 @top-center {
  14.                 content: element(header);
  15.                 }
  16.                 @bottom-left {
  17.                 content: element(footer);
  18.                 }
  19.                 }
  20.                 div.header {
  21.                 display: block; 
  22.                 position: running(header);
  23.                 }
  24.                 div.footer {
  25.                 margin-top:20px;                
  26.                 display: block;
  27.                 position: running(footer);
  28.  
  29.                 }
  30.                 .pagenumber:before {
  31.                 content: counter(page);
  32.                 }
  33.                 .pagecount:before {
  34.                 content: counter(pages);
  35.                 }
  36.  
  37.                 body {
  38.                 font-family: "Ubuntu", sans-serif;
  39.                 font-size: 14px;            
  40.                 margin:0; 
  41.                 padding:0;
  42.                 }
  43.                 th {
  44.                 min-height: 15px;
  45.                 max-height: auto;
  46.                 background:#ddd;
  47.                 }
  48.                 td {
  49.                 min-height: 15px;
  50.                 max-height: auto;
  51.                 }
  52.                 h1, h2, h3, h4{margin:0; padding:0;}
  53.                 p{margin:4px; padding:0;}
  54.  
  55.                 .slds-modal__container {
  56.                 width: 90% !important;
  57.                 min-width: 73rem !important;
  58.                 }	
  59.  
  60.             </style>
  61.         </head>
  62.         <body>            
  63.             <div class="header" style="border-bottom:2px #ccc solid; background:#ddd; padding:10px; 10px 10px 10px;">
  64.                 <br/>
  65.                 <table cellspacing="0" cellpadding="0" border="0" bordercolor="#22a2db" style="width: 100%; border-collapse: collapse; border-color: #22a2db; text-align:left;">
  66.                     <tr style="border-bottom:2px #ddd solid;">
  67.                         <td colspan="2"><img src="{!$Label.w3webLogo}" width="auto" height="auto" style="margin:-10px 0 0 30px;"/></td>
  68.  
  69.                         <td style="text-align:right;">
  70.                             <p>
  71.                                 <strong><a href="https://www.w3web.net/" target="_blank" style="color:#333; text-decoration: none;" rel="noopener noreferrer">Salesforce Application</a></strong>
  72.                             </p> 
  73.                             <p>
  74.                                 <a href="https://www.w3web.net/" target="_blank" style="color:#333; text-decoration: none;" rel="noopener noreferrer">A online cloud based platform</a>
  75.                             </p>
  76.                          </td>
  77.  
  78.                     </tr>
  79.  
  80.  
  81.                 </table>
  82.                 <br/>
  83.             </div>
  84.             <div class="footer">
  85.                 <div style="border-bottom:5px #22a2aa solid;">
  86.                     <table cellspacing="0" cellpadding="0" border="0" style="width: 100%; border-collapse: collapse; border-color: #333; text-align:left; border-bottom:5px #22a2db solid;">
  87.                         <tr style="font-size:16px;">
  88.                             <td style=" font-size:12px; text-align:center; ">
  89.                                 <div style="position:relative; border-top:1px #22a2db solid; padding-top:20px;">                                   
  90.                                     <p>
  91.                                        <strong><a href="https://www.w3web.net/" target="_blank" style="color:#2869e0;" rel="noopener noreferrer">Salesforce Application</a></strong>
  92.                                     </p> 
  93.                                     <p>
  94.                                         <a href="https://www.w3web.net/" target="_blank" style="color:#2869e0;" rel="noopener noreferrer">A online cloud based platform</a>
  95.                                     </p>
  96.                                     <br/>
  97.                                 </div>
  98.                             </td>
  99.                         </tr> 
  100.                     </table>
  101.                 </div>
  102.             </div>
  103.  
  104.             <div class="content">
  105.  
  106.                 <p style="font-size:17px;">
  107.                     <strong>w3web.net</strong> is the place where you can learn step-by-step about Blog, WordPress, Salesforce Lightning Component, Lightning Web Component (LWC), Visualforce, Technical of Computer Application, Salesforce Plugin, JavaScript, Jquery, CSS, Computer & Accessories, Software Configuration, Customization, Development and much <a href="https://www.w3web.net/" target="_blank" style="color:#333;" rel="noopener noreferrer"><strong>more…</strong></a>
  108.                 </p>
  109.                 <br/><br/>
  110.  
  111.                 <p>
  112.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  113.                 </p>
  114.                 <br/><br/>
  115.  
  116.                 <p>
  117.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  118.                 </p>
  119.  
  120.                 <br/><br/>
  121.                 <p>
  122.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  123.                 </p>
  124.  
  125.                 <p>
  126.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  127.                 </p>
  128.                 <br/><br/>
  129.  
  130.                 <p>
  131.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  132.                 </p>
  133.  
  134.                 <br/><br/>
  135.                 <p>
  136.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  137.                 </p>
  138.  
  139.                 <p>
  140.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  141.                 </p>
  142.                 <br/><br/>
  143.  
  144.                 <p>
  145.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  146.                 </p>
  147.  
  148.                 <br/><br/>
  149.                 <p>
  150.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  151.                 </p>
  152.  
  153.                 <p>
  154.                     Vijay Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  155.                 </p>
  156.                 <br/><br/>
  157.  
  158.  
  159.                 <!--End page-break -->
  160.  
  161.                 <p>
  162.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  163.                 </p>
  164.  
  165.                 <br/><br/>
  166.                 <p>
  167.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  168.                 </p>
  169.  
  170.                 <!--Start page-break -->
  171.  
  172.                 <div style="page-break-after:always;"></div>
  173.                 <br/><br/>
  174.  
  175.  
  176.                 <p>
  177.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  178.                 </p>
  179.                 <br/><br/>
  180.  
  181.                 <p>
  182.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  183.                 </p>
  184.  
  185.                 <br/><br/>
  186.                 <p>
  187.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  188.                 </p>
  189.  
  190.  
  191.  
  192.             </div>
  193.         </body>
  194.     </html>    
  195. </apex:page>

 

Further post that would you like to learn in Salesforce

 


 

FAQ (Frequently Asked Questions)

How do I add a footer to a Visualforce page rendered as PDF?

After the @page definition, we can add the information to the footer inside with class='footer'. The 'footer' class will set the content inside the to the bottom-center of the page and display it on every page. We also added span id='pageNum' which shows the page number after the company information.

How to save a VF page rendered as PDF to notes and attachments?

Save the Attachment as PDF using Apex Class and Visualforce Page on click button in Salesforce. You can use the PageReference. getContentAsPDF() method in Apex to render a Visualforce page as PDF data. Then use Apex code to convert that PDF data to an email attachment, a document, a Chatter post, and so on.

What is the use of render in VF page?

A Visualforce component in a VF page can be displayed or hidden by using a rendered attribute. Rendered is bound to a Boolean variable in the controller which can be switched between true and false making the VF component display or hide depending on a Boolean value.

Related Topics | You May Also Like

 
Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 
  

Our Free Courses →

👉 Get Free Course →

📌 Salesforce Administrators

📌 Salesforce Lightning Flow Builder

📌 Salesforce Record Trigger Flow Builder

👉 Get Free Course →

📌 Aura Lightning Framework

📌 Lightning Web Component (LWC)

📌 Rest APIs Integration



Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment