Pdf Coldfusion:在使用cfdocument时,如何在新页面上包含HTML表格标题?

Pdf Coldfusion:在使用cfdocument时,如何在新页面上包含HTML表格标题?,pdf,coldfusion,page-break,Pdf,Coldfusion,Page Break,我在页面上有一个表,其中包含从查询生成的数据。这使得生成的行数无法预测 当使用cfdocument将页面输出为PDF时,表格通常在分页符处一分为二 为了清晰起见,有什么简单的方法可以在新页面上包含表格标签吗?我不得不使用cfdocument,在某些情况下使其可用是一件非常困难的事情 我相信您的问题的答案可以在本页上找到,因为您知道每页静态行高上有多少条记录: 这里还有一些关于cfdocument的其他问题,我已经发布并处理过了,希望能有所帮助 试试这个方法,我已经用过了 <cfset a

我在页面上有一个表,其中包含从查询生成的数据。这使得生成的行数无法预测

当使用cfdocument将页面输出为PDF时,表格通常在分页符处一分为二


为了清晰起见,有什么简单的方法可以在新页面上包含表格标签吗?

我不得不使用cfdocument,在某些情况下使其可用是一件非常困难的事情

我相信您的问题的答案可以在本页上找到,因为您知道每页静态行高上有多少条记录:

这里还有一些关于cfdocument的其他问题,我已经发布并处理过了,希望能有所帮助


试试这个方法,我已经用过了

<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>

只是添加了一些在CF10中不起作用的东西,我认为它使用了与CF8和CF9相同的CFdoc渲染器:

使用css:after-CFdocument在header元素之后添加内容不支持css3 不支持ad{display:表头组;} 在表输出中使用javascript动态添加标题行,pdf呈现程序不会执行js 在cfdocument正文中测试cfdocument.currentpagenumber该变量似乎只存在于页眉和页脚中 在soundsOfTheDot中添加a回答了他的另一个问题,他说这是可行的,但在我的测试中,渲染器似乎在每个页面的末尾关闭表,然后重新打开它 使用测试在中添加一个表,例如在第一个页面之后将其插入所有页面。如果您可以硬编码列宽,使两个表对齐,并确保此假标题与实际表之间没有间隙,则这几乎可以完成任务
我希望这样可以节省一些时间。

我的PDF恰好适合每页21行,因此我确保当前的21模行等于0。注意,我从每页的一个新表开始,因此在使用上一页的表和分页符的结束标记和之后,我将新表和仅一个放在中。然后我跟着它,瞧,它就像一个符咒。我还添加了一个很好的页脚到PDF只是为了好玩

<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>

桌子上的行总是有完全相同的高度吗?是的。总是一样高。我想你不明白这个问题。为什么你在2020年仍然使用ColdFusion?我知道ColdFusion似乎过时了,但它恰好是我工作场所使用的主要语言。它还有很多好的特性。