【问题标题】:Coldfusion : How to include HTML table headers on new page when using cfdocument?Coldfusion:使用 cfdocument 时如何在新页面上包含 HTML 表格标题?
【发布时间】:2013-02-13 09:53:52
【问题描述】:

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

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

为了清晰起见,是否有任何简单的方法可以在新页面上包含表格标签?

【问题讨论】:

  • 表格行是否总是具有完全相同的高度?
  • 是的。始终保持相同的高度。

标签: pdf coldfusion page-break


【解决方案1】:

我不得不使用 cfdocument 相当多的时间,让它在某些情况下可用可能是一个真正的负担。

我相信您的问题的答案可以在此页面上找到,因为您知道每页上有多少条记录(静态行高): COLDFUSION: cfdocument and forcing a pagebreak

以下是我发布并解决的有关 cfdocument 的其他一些问题,希望对您有所帮助。

【讨论】:

    【解决方案2】:

    试试这个方法,我用过

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

    【讨论】:

    • 我认为你没有理解这个问题。
    【解决方案3】:

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

    • css:after在header元素后添加内容(CFdocument不支持css3)
    • 头{显示:表头组; }(不支持)
    • 在表格输出中使用javascript动态添加标题行(pdf渲染器不执行js)
    • 在 cfdocument 正文中测试 #cfdocument.currentpagenumber#(该变量似乎只存在于页眉和页脚中)
    • 在(soundsOfTheDot 回答他的另一个问题说这有效,但在我的测试中渲染器似乎在每页末尾关闭表格然后重新打开它)中添加 李>
    • 添加一个表在测试中就像在第一个页面之后的所有页面上插入它(这几乎可以完成工作,如果你可以硬编码你的列宽以便两个表对齐并确保这个假表头和实际表之间没有差距)

    我希望这可以节省一些时间。

    【讨论】:

      【解决方案4】:

      我的 PDF 恰好适合每页 21 行,所以我确保当前行 MODULO 21 等于 0。请注意,我每页都从一个新表开始,所以我将新的 &lt;table&gt;&lt;thead&gt; 放在一起在使用 &lt;/tbody&gt;&lt;/table&gt; 的结束标签作为前一页的表格和分页符之后的 &lt;cfif&gt; 内。然后我用&lt;tbody&gt; 跟随它,瞧,它就像一个魅力。我还为 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 似乎已经过时,但它恰好是我工作场所使用的主要语言。它还有很多不错的功能。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-13
      相关资源
      最近更新 更多