Ye Meri Life Hai – Chirag Mehta

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

July 5th, 2010

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

Comments

4 Comments

RSS
  • Pragya says on: July 5, 2010 at 3:43 pm

     

    Its really very helpful code and can be easily used.

  • Ivan says on: August 22, 2010 at 2:21 pm

     

    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!

  • Ruben says on: September 10, 2010 at 9:28 am

     

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

  • Ruben says on: September 10, 2010 at 9:29 am

     

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

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

*