6

I am generating a PDF file dynamically from html/css using the cfdocument tag. There are blocks of content that I don't want to span multiple pages.

After some searching I found that the style "page-break-inside" is supported according to the docs. However in my testing the declaration "page-break-inside: avoid" does no good.

Any suggestions on getting this style declaration to work, or have alternative suggestions?

Here is an example. I would expect the content in the div tag not to span a page break but it does. The style "page-break-inside: avoid" is not being honored.

<cfdocument format="flashpaper">
    <cfloop from="1" to="10" index="i">
        <div style="page-break-inside: avoid">
            <h1>Table Label</h1>
            <table>
                <tr><td>label</td><td>data</td></tr>
                <tr><td>label</td><td>data</td></tr>
                <tr><td>label</td><td>data</td></tr>
                <tr><td>label</td><td>data</td></tr>
                <tr><td>label</td><td>data</td></tr>
                <tr><td>label</td><td>data</td></tr>
                <tr><td>label</td><td>data</td></tr>
                <tr><td>label</td><td>data</td></tr>
                <tr><td>label</td><td>data</td></tr>
            </table>
        </div>
    </cfloop>
</cfdocument>
Adam Lear
  • 38,111
  • 12
  • 81
  • 101
Dan Roberts
  • 4,664
  • 3
  • 34
  • 43

3 Answers3

4

Not an ideal solution, but I've forced page breaks before blocks that need to be kept together. Use page-break-before to trigger a page break before the block.

I don't think there is a way to specifically forbid breaking within (that is honored by the PDF engine).

Ben Doom
  • 7,865
  • 1
  • 27
  • 30
  • I hoped this wouldn't be necessary -- the content height is very dynamic. I guess if this is the only solution then I'll just have to estimate height somehow... or see if what I'm doing would work better in the report builder. – Dan Roberts Mar 17 '09 at 17:28
  • Frustrating that the docs say this style is supported and it fits this situation perfectly but it doesn't actually work. Submitting a bug report now. – Dan Roberts Mar 17 '09 at 17:32
1

In case you haven't solved this already, I had the same problem and came across this solutions in the CF8 Live Docs and it seems to have worked for me.

"Simply putting a

<br> 

after the image yet inside the TD worked fine and the images no longer are cut."

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_d-e_05.html

invertedSpear
  • 10,864
  • 5
  • 39
  • 77
0

Wrap the contents of your cells with divs (ie. <td><div>Cell contents</div></td>). See my answer on a similar thread: COLDFUSION: cfdocument and forcing a pagebreak

Community
  • 1
  • 1
Jonathan Wilson
  • 4,138
  • 1
  • 24
  • 36