function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

PDF Generation - Page Breaks and Formatting

I've recently been wanting to generate a PDF from a visualforce page but with page breaks in various places.  Is this something that I can do using CSS or will I have to have lots of <br /> tags in my page?
The trick is to put every thing you want on a single page within <div> tags.

Then, use this <div style="page-break-before:always"> for the starting <div> tag.

The tricky part is ensuring that the text before the closing </div> tag does not exceed a page. Otherwise, you could have two page breaks.

But this works pretty well for me.

Here is a complete example.

<apex:page controller="YourController" standardstylesheets="true" renderas="pdf">
<apex:repeat value="{!biglist}" var="sublist" first="1">
<apex:repeat value="{!sublist}" var="item" rows="1">
<div style="page-break-before:always">
<table width="700" align="center">
    <table width="100%">
        <tr><td align="center" height="30" valign="center"><b><i>Additional Items</i></b></td></tr>
    <table width="100%" height="10"><tr><td></td></tr></table>    
    <table width="100%" border="1" cellpadding="5">
            <th align="center" width="10%">Item No.</th>
            <th align="center" width="10%">Quantity</th>
            <th align="center" width="50%">Description</th>
            <th align="center" width="30%">Slab Number</th>
        <apex:repeat value="{!subList}" var="item">
            <td align="center">{!item.number}</td>
            <td align="center">{!item.quantity}</td>
            <td align="left">{!item.Name}</td>
            <td align="left">{!item.Price}</td>


Is there any way to repeat the header information e.g. page# , Logo, document number, Column headings for table data on every page.
Ron HessRon Hess
Yes, take a look at this article

read down to casehistoryprint
and note the css file that goes with it, this has the CSS page syntax

here is another example that uses css along with a pdf render.

Message Edited by mr209204 on 09-18-2008 10:26 AM
This is probably asking way too much (I like to see where the line is :smileywink:) but is there any way to create a contents page at all? I was thinking about creating a PDF that contains a lot of information and it would be nice if I could put it into different sections then have a contents page so people could click a link to the section they are interested in.