Activity Forums Salesforce® Discussions How to print pdf format in page number as a predefined format for a Visualforce page?

  • Neha

    Member
    March 29, 2018 at 5:12 am

    Hi Amresh,

    With the help of formatting the VisualForce Page rendered as PDF with CSS, we can do that.

    VisualForce allows you to create PDF documents (<apex:page RenderAs="PDF">), but those files can be easily manipulated with CSS, for example, you can break a document on different pages, you can set footers and headers, set the page size, and add page numbering.
    You can find a very good document on how to use CSS to format PDF files here: http://www.antennahouse.com/CSSInfo/CSS-Page-Tutorial-en.pdf

    This page creates a PDF file that:

    • Uses "Letter" as the paper size
    • Has margins of 1/4 centimetres
    • Has a title on every page
    • Every page shows the page number in this format (page # of #)
    • Controls what content goes on each page.

    Sample Code:

    <apex:page renderAs="pdf" showHeader="false" sidebar="false" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false">
    <html>
    <head>
    <style>
    @page {
    size: letter;
    margin: 25mm;
    @top-center {
    content: "Sample";
    }
    @bottom-center {
    content: "Page " counter(page) " of " counter(pages);
    }
    }
    .page-break {
    display:block;
    page-break-after:always;
    }
    body {
    font-family: Arial Unicode MS;
    }
    </style>
    </head>
    <body>
    <div class="page-break">Page A</div>
    <div class="page-break">Page B</div>
    <div>Page C</div>
    </body>
    </html>
    </apex:page>

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos