Sunday, May 17, 2009

Formating Page Created using <apex:page RenderAs="PDF">

VisualForce allows you to create PDF documents, but did you know those files can be easily manipulated with CSS, for example you can break a document on different pages, you can set footers and headers, you can set the page size, you can add page numbering…

You can find a very good document on how to use CSS to format PDF files here

This page creates a PDF file that:

  • Users Letter as the paper size
  • Has margins of 1/4 centimeters
  • Has a title on every page
  • Every page shows the page number in this format (page # of #)
  • Control what content goes on each page.
VisualForce Page:
<apex:page renderAs="PDF">
    <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>
    <div class="page-break">Page A</div>
    <div class="page-break">Page B</div>
    <div>Page C</div>
</apex:page>

No comments:

Post a Comment