【问题标题】:Making the header of tables repeat when generating a PDF in coldfusion在coldfusion中生成PDF时使表头重复
【发布时间】:2014-03-07 20:19:21
【问题描述】:

我正在生成一份报告,其中包含许多不同的表格来显示不同的数据集。 通常表格会流入第二或第三页,有谁知道如何使表格标题重复?

我无法使用记录计数来确定何时插入标题信息,因为数据是随机长度的,因此带有包装文本的记录可能会占用页面上的 10 行。 我曾尝试将表头存储为变量并使用 ,但它会在每一页的顶部显示最后一个表的表头。

这里有一些示例代码来说明问题:

<cfoutput>
<cfdocument format="PDF" name="TestDetailReport" marginBottom = "1" marginLeft = ".3" marginRight = ".3" marginTop = ".5" orientation="landscape">
    <cfdocumentsection name = "TA Overview" >
        <cfdocumentitem type = "header">
            <table width="100%">
                <tr>
                    <td width="40%">Generated by:</td>
                    <td width="60%" align="left">cfdocumentitem type = "header"</td>
                </tr>
            </table>
        </cfdocumentitem>

        <!--- There will be several sections like this, each with thier own header --->
        <body style="margin: 0px">
            <table style="width:100%;">
                <!-- table header to be repeated on each PDF page -->
                <thead align="left" style="display: table-header-group">
                    <tr>
                        <td colspan="2" style=" text-align:center;color:red">Make the header of this section repeat when the table goes into the next page</td>
                    </tr>
                    <tr>
                        <td style="text-align:center;color:red">Row Number</td>
                        <td style="text-align:center;color:red">This column contains text of random length</td>
                    </tr>
                </thead>
                <!-- table body -->
                <tbody>
                    <cfloop from="1" to="50" index="Index">
                    <tr style="border-bottom:thin;">
                        <td>Row #Index#</td>
                        <td><cfloop from="0" to="#RandRange(1, 50)#" index="randomText">#Index# blah </cfloop></td>
                    </tr>
                    </cfloop>
                </tbody>
            </table>
        </body>

        <cfdocumentitem type = "footer">
            <table width="100%">
                <tr>
                    <td width="12%">Generated by:</td>
                    <td width="13%" align="left">#cgi.auth_user#</td>
                    <td width="50%" rowspan="3" align="left">img src="file:///#ExpandPath('logo.gif')#"</td>
                    <td width="25%" rowspan="3" align="justify">Printed Copy as Part of Prepbook is a Controlled Document. All Other Copies are Uncontrolled.</td>
                </tr>
                <tr>
                    <td>Date:</td>
                    <td align="left">#DateFormat(now(), "medium")#</td>
                    <!--- <td align="right"></td> --->
                </tr>
                <tr>
                    <td>Page:</td>
                    <td align="left">#cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</td>
                    <!--- <td align="right"></td> --->
                </tr>

            </table>
        </cfdocumentitem>
    </cfdocumentsection>
</cfdocument>

【问题讨论】:

  • 如果您想尝试一下,可以使用 CF Report Builder... ;)
  • 就我个人而言,我会使用 XSL 将其转换为 XSL FO,并利用所有支持 XSL FO 的产品已经提供的所有高级格式特性(开箱即用)......比如重复表头。

标签: coldfusion pdf-generation cfdocument


【解决方案1】:

我认为 PDF 生成器不够聪明,无法做到这一点。

我同意 James A 在此处使用输入代码 CFDocItem 来控制何时发生分页符 - 这是我找到的唯一解决方法。

过去,我们允许用户自行指定何时发生分页符。这对我们有用,因为无论输出什么数据,它们创建的分页符仍然有效(因为它是统计数据,并且它的大小变化不大 - 与大量文本不同)。

一个建议(虽然可能是有史以来最糟糕的想法)可能是破解 PDF 标题以包含您的表格标题 [dodges things being throws]

【讨论】:

  • 感谢您的所有好评。我只是想结束这个循环。这与我实现解决方案的方式最接近(创建 PDF,然后打开并重新组合,删除空白空间并添加标题),但这是一个可怕的混乱。真正的答案是 ColdFusion 没有必要的工具来创建真正可变内容的报告。它可以很好地处理基本的报告需求,但它没有很多工具来执行格式化任务。
【解决方案2】:

&lt;cfdocumentitem type= "pagebreak&gt; 提供将文档分成页面的功能。我怀疑您每次都必须重新输出表格标题。

见:

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7758.html

【讨论】:

    【解决方案3】:

    几个解决方案

    • 创建一个逻辑,如果表中有超过 n 条记录,将再次输出表头。这不是一个好的解决方案,我总是会跳过使用 cfdocument 来编写我的 pdf 报告,但它可以做到。您将面临 cfdocument for start 中的 html 问题。
    • 更好的解决方案是使用 ColdFusion Builder。
    • 也许最好的解决方案是使用ColdFusion Report Builder alternative 但这将花费时间来设置和运行所有内容。

    如果您决定使用报表生成器方案,这可能是最适合您的方案。这是你必须做的:

    第 1 步 - 在 ColdFusion Builder 中为您在报告中拥有的每个不同表创建 cfr(ColdFsuion Report Builder 模板文件)。这很简单。这里有一些docs

    第 2 步 使用cfreport为每个“表”生成临时pdf,然后使用ddx合并这些文件并添加/设计报告的页眉和页脚

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-18
      • 1970-01-01
      • 2019-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-26
      相关资源
      最近更新 更多