5

I have a table on a page with data generated from a query. This makes it unpredictable how many rows will be generated.

When using cfdocument to output the page as a PDF the table is often cut in two on the page break.

Is there any easy way to include the table labels on the new page for the purpose of clarity?

blarg
  • 3,773
  • 11
  • 42
  • 71

4 Answers4

4

I've had to work with cfdocument quite a bit and making it usable in certain situations can be a real bear.

I believe the answer to your question can be found on this page since you know how many records will be on each page (static row height): COLDFUSION: cfdocument and forcing a pagebreak

Here are some other questions I've posted and worked through concerning cfdocument, hope they help.

Community
  • 1
  • 1
genericHCU
  • 4,394
  • 2
  • 22
  • 34
0

try this approach, I have used it

<cfset amount="6" />
<cfdocument
format="pdf"
unit="cm"
pageType="A4"
filename="#path##name#.pdf">
 <cfoutput>
    <cfloop from="1" to="#amount#" index="i">
        <cfset filename = "#name#_#i#" />
        <cfimage
            action="convert"
            destination="#path#codes/#filename#.jpg"
            source="#path#codes/#filename#.png" />
        <img src="file://#path#codes/#filename#.jpg" style="width: 3.58cm; margin: 0 0.2cm 0.5cm;">
    </cfloop>
</cfoutput>

0

Just adding some things that DON'T work (in CF10, which i think uses the same CFdoc renderer as CF8 & CF9):

  • adding content after the header element with css:after (CFdocument doesn't support css3)
  • thead { display: table-header-group; } (not supported)
  • using javascript within the table output to add a header row dynamically (the pdf renderer doesn't execute js)
  • testing #cfdocument.currentpagenumber# in the cfdocument body (that variable seems only to exist in the header and footer)
  • adding a in the (soundsOfTheDot answered his other question saying that this worked, but in my tests the renderer seems to close the table at the end of each page then re-open it)
  • adding a table in the with a test like to insert it on all pages after the first one (this almost does the job, if you can hard-code your column widths so the two tables line up and ensure there is no gap between this faux header and the actual table)

I hope that saves some hours.

andrew lorien
  • 146
  • 1
  • 7
0

My PDF happened to fit 21 rows per page, so I made sure the current row MODULO 21 equaled 0. Notice I start with a new table each page, so I put the new <table> along with only a <thead> inside the <cfif> after using the closing tags of </tbody> and </table> for the previous page's table and the pagebreak. Then I follow it with the <tbody>, and voila, it works like a charm. I also added a nice footer to the PDF just for funsies.

<cfquery name="getDeletedBarcodes" datasource="#application.dsn#">
    SELECT * FROM deletedRecords
</cfquery>
<cfdocument filename="reports/DeletedBarcodes.pdf" format="PDF" overwrite="true">
    <cfif getDeletedBarcodes.RecordCount NEQ 0>
        <h2 align="center" style="text-decoration: underline; font-weight: bold">Deleted Barcode Records</h2>
        <table class="deletedBarcodesTable" border="1" style="margin-top: 10px" rules="rows">
            <thead>
                <tr>
                    <th>Barcode</th>
                    <th>Building</th>
                    <th>Room</th>
                    <th>Location</th>
                    <th>Shelf</th>
                    <th>Inventoried</th>
                    <th>Deleter Name</th>
                    <th>Time Deleted</th>
                    <th>Reason Deleted</th>
                </tr>
            </thead>
    <cfelse>
        <p>There are no records to show that have deleted barcodes.</p>
    </cfif>
    <cfloop query="getDeletedBarcodes">
        <cfoutput>
            <cfif getDeletedBarcodes.currentRow MOD 21 EQ 0>
                </tbody></table>
                <cfdocumentitem type="pagebreak" />
                <table class="deletedBarcodesTable" border="1" style="margin-top: 10px" rules="rows">
                    <thead>
                        <tr>
                            <th>Barcode</th>
                            <th>Building</th>
                            <th>Room</th>
                            <th>Location</th>
                            <th>Shelf</th>
                            <th>Inventoried</th>
                            <th>Deleter Name</th>
                            <th>Time Deleted</th>
                            <th>Reason Deleted</th>
                        </tr>
                    </thead>
                    <tbody>
            </cfif>
            <tr>
                <td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "Barcode") OR NOT len(Barcode)><strong style="color: red">N/A</strong><cfelse>#Barcode#</cfif></td>
                <td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "Building") OR NOT len(Building)><strong style="color: red">N/A</strong><cfelse>#Building#</cfif></td>
                <td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "Room") OR NOT len(Room)><strong style="color: red">N/A</strong><cfelse>#Room#</cfif></td>
                <td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "Location") OR NOT len(Location)><strong style="color: red">N/A</strong><cfelse>#Location#</cfif></td>
                <td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "Shelf") OR NOT len(Shelf)><strong style="color: red">N/A</strong><cfelse>#Shelf#</cfif></td>
                <td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "Inventoried") OR NOT len(Inventoried)><strong style="color: red">N/A</strong><cfelse>#LEFT(Inventoried, 10)#</cfif></td>
                <td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "DeleterName") OR NOT len(DeleterName)><strong style="color: red">N/A</strong><cfelse>#DeleterName#</cfif></td>
                <td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "TimeDeleted") OR NOT len(TimeDeleted)><strong style="color: red">N/A</strong><cfelse>#TimeDeleted#</cfif></td>
                <td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "ReasonDeleted") OR NOT len(ReasonDeleted)><strong style="color: red">N/A</strong><cfelse>#ReasonDeleted#</cfif></td>
            </tr>
        </cfoutput>
    </cfloop>
    <cfdocumentitem type="footer"> 
        <cfoutput>
            <div style="border-top: 5px solid black; border-top-width: 100vw">
                <span style="left: 0; float: left">#DateFormat(Now(), "full")#</span>
                <span style="right: 0; float: right">Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</span>
            </div>
        </cfoutput>
    </cfdocumentitem>
</cfdocument>
Max Voisard
  • 1,685
  • 1
  • 8
  • 18