+ Start a Discussion
XactiumBenXactiumBen 

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?
ClaiborneClaiborne
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.

Code:
<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">
<tr><td>
    <table width="100%">
        <tr><td align="center" height="30" valign="center"><b><i>Additional Items</i></b></td></tr>
    </table>
    <table width="100%" height="10"><tr><td></td></tr></table>    
    <table width="100%" border="1" cellpadding="5">
        <tr>
            <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>
        </tr>
        <apex:repeat value="{!subList}" var="item">
        <tr>
            <td align="center">{!item.number}</td>
            <td align="center">{!item.quantity}</td>
            <td align="left">{!item.Name}</td>
            <td align="left">{!item.Price}</td>
        </tr>
        </apex:repeat>
    </table>                                       
</td></tr>
</table>
</div>
</apex:repeat>
</apex:repeat>
</apex:page>

 

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

http://wiki.apexdevnet.com/index.php/Visualforce_CaseHistoryTimeline

read down to casehistoryprint
and note the css file that goes with it, this has the CSS page syntax
mr209204mr209204
http://wiki.apexdevnet.com/index.php/Visualforce_Quote2PDF

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


Message Edited by mr209204 on 09-18-2008 10:26 AM
XactiumBenXactiumBen
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.