[SalesForce] pageblocktable rows spanning over page breaks when rendered as pdf

I have a pageblocktable that is being rendered as a pdf. The PDF is set as A4 landscape with small margins and page numbering in a style sheet. The problem is that rows in the pageblocktable span the page break, any text above and below is split on the line, making it difficult to read that line. The lines heights are content-dependent, so I cannot add some sort of padding at a set point to force the page breaks where I want them.

The problem as I interpret it is that pageblocktables are contiguous, if you display one on a normally rendered page it will be one big block without breaks. When you say to render as PDF it simply takes the visuals, puts them into a graphic format, then slices it into pieces that fit the page margins.

Is there anything I can do in the style sheet or the page code to get the engine to be aware of the page break?

my somewhat redacted page code:

<apex:page controller="MyCustomController" title="My List" renderAs="pdf">
<apex:stylesheet value="{!URLFOR($Resource.pdfresources)}"/>
<apex:form >
<apex:pageBlock title="My List" mode="Edit" >
<apex:pageBlockTable value="{!DataList}" var="data" width="100%" headerClass="tableHeader" cellPadding="2px">
columns here

Here's a screenshot, you can clearly see the bleed-over.
enter image description here

Best Answer

You can set page breaks via CSS, though you may have to change your page's structure to accomplish this. There is a good example on Developerforce that demonstrates this. It works as follows:

  1. A two-dimensional array
  2. Using <apex:repeat> or a similar construct
  3. Having your controller populate the 2-d array

In your controller:

  1. Execute the SOQL to generate your list of results
  2. Populate the 2-D array as follows
    1. Each outer element represents a page worth of results
    2. Each inner array represents the rows to display

In your VF page:

  1. An outer loop to generate each page
  2. An inner loop to generate each row
  3. CSS to provide page-break-after:always; at the end of each page

The number of elements that you can fit on a page will vary and require some experimentation to get right. Also note that working in Development Mode breaks the CSS as I found out the hard way.

Related Topic