Be Good & Do Good!

Page Break, Page number and Page layout Styles in Visualforce PDF Templates

1. Page Break
While generating PDF template from Visualforce, if you want to give the page break ,below code snippet is very useful.
You can use the page break style properties to control where the browser will insert a page break. The Force.com PDF content converter will carry that over to the PDF.

<apex:page renderas="pdf">
<div style="page-break-after:always;">
This is page one
</div>
</apex:page>

2. Page layout and Page number
The following snippet shows you have to switch the PDF page layout to landscape and add page numbers to your Visualforce page. Use the below code in CSS of Visualforce page.

@page {
/* Landscape orientation */
size:landscape;

/* Put page numbers in the top right corner of each page in the pdf document. */
@top-right
{
content: “Page ” counter(page);
}
}

Source : Kyle Roche / Pragya Kumari

5 Comments

  1. Pragya

    Its really very helpful code and can be easily used.

  2. Ivan

    That’s useful but it doesn’t work for Word/Excel documents (I mean ContentType=”application/msword”). Is there any opportunity to use it for such documents? Thanks!

  3. Ruben

    Can we include the current date in the footer of a PDF generated from Visualforce?

  4. Ruben

    Also, can we include the company logo in the header of the PDF?

  5. jeet

    here is my code

    on the insurance field contents are having bullets. I wants to put a page break after when a bullet will come.
    like this:-
    • Description1
    • Description1
    • Description1

    but this is coming as a paragraph on the PDF

Leave a Reply

Your email address will not be published. Required fields are marked *