Kyle
Roche
The Visualforce page component defines a renderAs attribute that supports certain content converters. This is extremely useful when automatically printing forms, receipts, reports, etc. Often, we're asked to create nicely formatted forms that span multiple pages. If you leave the control of page breaks to the browser unexpected things can happen. This is an easy solution to solve with some basic CSS. 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.
Here's the basic code to demonstrate how this works. Create a new Visualforce Page called MultiPagePDF. Add the following code to the page:
<apex:page renderas="pdf">
<div style="page-break-after:always;">
This is page one
</div>
<div style="page-break-after:always;">
This should be rendered as page two
</div>
And, finally... page three
</apex:page>
This should yield something like this illustration when rendered. Some natural extensions to this posting would be to dynamically insert these into the page. Inserting <div> tags and binding the style to an APEX property could be one way to accomplish this. You would pass back a blank style in some cases and return a string with the value of "page-break-after:always" for <div> sections where a break is needed.
As a quick side note, you can get a bit more advanced with the Page formatting via CSS. The following snippet shows you have to switch the page layout to landscape and add page numbers to your Visualforce page. This was found in the Case History Timeline example.
@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);
}
}






4 comments:
Thanks
iliyas.patel@gmail.com
Can we count page Number based on tag.
Say example visual force generates PDF from list button where 2 records are selected and result page is totally 5.
With help apex repeat tag, for the first record 3 pages and second record it is next 2 pages generated in a single file.
I want count a page number in a PDF doc as Page 1 of 3, 2 0f 3, 3 0f 3 and then again 1 of 2 and 2 of 2.
Is it possible?
Suppose I got more than 50 pages, each page represents opportunity line item.
So if I generate one page each for each line item attached to an opportunity. Or may be if the no of line items exceeds 100, than number of pages in pdf will be 100, Will it result in view state error ?
Can we create a table of index?
Post a Comment