Loading

Add page header or footer into a Visualforce page rendered as PDF

Julkaisupäivä: Oct 13, 2022
Kuvaus

You can use the Visualforce option to render the page as a PDF for printing or downloading. To include a header or footer element that includes the details such as "Page 1 out of 2"  or an additional title to remind the user what page they printed, you could use the following sample code. 

Ratkaisu

Sample code for header and footer

<apex:page renderAs="pdf" applyBodyTag="false" standardController="Account">
        <head>
                <style type="text/css" media="print">
                       @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>Account name is: {!Account.name} ----------- and the date is {!TODAY()}</div>
           </div>
           <div class="footer">
                <div>Page <span class="pagenumber"/> of <span class="pagecount"/></div>
          </div>
          <div class="content">
               <p>Actual page body information.</p>
          </div>
</apex:page>

Additional resources

Knowledge-artikkelin numero

000385370

 
Ladataan
Salesforce Help | Article