Skip to content

Instantly share code, notes, and snippets.

@kevanmoothien
Last active March 21, 2023 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevanmoothien/300da55b5dbce2d7d7e2bf8662c7fefd to your computer and use it in GitHub Desktop.
Save kevanmoothien/300da55b5dbce2d7d7e2bf8662c7fefd to your computer and use it in GitHub Desktop.
A visualforce template with header and footer for pdf
<apex:page applyHtmlTag="false"
           showHeader="false"
           renderAs="pdf">
    <html>
        <head>
            <style>
                @page {
                    size: A4;
                    margin-top: 2cm;
                    margin-bottom: 2cm;
                    margin-left: 3cm;
                    margin-right: 3cm;

                    @top-center {
                        content: element(header);
                    }
                    @bottom-left {
                        content: element(footer);
                    }
                }
                div.header {
                    position: running(header);
                }
                div.footer {
                    display: block;
                    position: running(footer);
                }
                .pagenumber:before {
                    content: counter(page);
                }
                .pagecount:before {
                    content: counter(pages);
                }
            </style>
        </head>
        <body>
            <div class="header">
                <div>This is the header</div>
                <hr />
            </div>
            <div class="footer">
                <hr />
                <div>This the footer with page number</div>
                <div>Page <span class="pagenumber"/> of <span class="pagecount"/></div>
            </div>
            <div class="content">
                <p>Actual page body information.</p>
            </div>
        </body>
    </html>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment