COLDFUSION: cfdocument and forcing a pagebreak

后端 未结 4 1155
孤独总比滥情好
孤独总比滥情好 2020-12-19 04:58

I am creating a dynamic PDF in ColdFusion and having an issue with \"pagebreak\". The page in question could have 1 record, or up to 60+ records. Each record is displayed

相关标签:
4条回答
  • 2020-12-19 05:12

    Try adding a style="page-break-inside: avoid;" to any element that you don't want to be split between 2 pages.

    For instance,

    <tr style="page-break-inside: avoid;">
       <td>#Title#</td><td>#Price#</td>
       <td colspan="2">#Description#</td>
    </tr>
    
    0 讨论(0)
  • 2020-12-19 05:14

    For me, after trying all the tricks and forum hints etc. - the only thing that worked in cf8 for larger blocks of code (including images, tables, div block etc.) is:

    • wrap the non page breaking part with

      <div>...</div>

    • but a super simple <br> after it in a new line (in code) e.g.

      <div> ... your stuff ... </div> <br>

    that worked, hell knows why...

    0 讨论(0)
  • 2020-12-19 05:22

    After wrestling with this issue on and off for several months, I've discovered that wrapping the contents of a td with a div (ie.<tr><td><div>Cell Contents</div></td></tr>) will prevent a page-break inside the row. With this setup, a page-break that would normally split the row between pages will instead fall before the row, creating a little extra whitespace at the end of the first page and placing the row at the beginning of the next page.

    Note about rows with multiple cells: A single td-nested div is sufficient to cause the above behavior for the whole row.

    <tr>
        <td>Blah blah blah blah blah</td>
        <td>Gnar gnar gnar gnar gnar</td>
        <td><div>Soda POP soda POP soda POP</div></td>    <!--- the fix --->
        <td>Stellar!</td>
    </tr>
    
    0 讨论(0)
  • 2020-12-19 05:29

    You are hiding the 9th record because you are choosing between displaying it and showing it:

    if 9th record
        break page
    else
        show record
    end if
    

    What you want is more like:

    <cfoutput query = "sqllookup">
        <!--- this is the 9th row, because 9 mod 9 is 0 --->
        <cfif not sqllookup.currentrow mod 9>
            <cfdocumentitem type="pagebreak" />
        </cfif>
        <tr>
            <td>#Title#</td><td>#Price#</td>
            <td colspan="2">#Description#</td>
        </tr>
    </cfoutput>
    
    0 讨论(0)
提交回复
热议问题