【问题标题】:Apply page margin only to the last page in ColdFusion PDF document仅将页边距应用于 ColdFusion PDF 文档的最后一页
【发布时间】:2014-10-05 17:53:10
【问题描述】:

我正在使用<cfdocument> 在 ColdFusion 中生成 PDF,我只想在最后一页上显示页脚。我找到了一个解决方案here,效果很好,并且只会在最后一页显示页脚。

如果您的页脚很长,您需要在<cfdocument> 标签中添加marginbottom 以定义空间,例如:

<cfdocument format="PDF" unit="in" marginbottom="1.5" ... >

这意味着每一页的底部都会有 1.5 英寸的空白空间,有没有办法只将该空间应用到最后一页?

【问题讨论】:

  • 如果您只在最后一页的底部显示文本,它并不是真正的页脚。正确的?那么为什么不在&lt;cfdocument&gt; 代码块的末尾添加文本呢?这样您就不需要定义影响每个页面的 marginbottom。
  • @Miguel-F 这样页脚将在内容结束后立即结束,并且可能位于页面中间的某个位置,除非它绝对定位为底部:0。使用绝对定位,如果它碰巧最终出现在页脚所在的位置,它可能会掩盖内容。
  • 您是否尝试过在&lt;cfdocument&gt; 代码块末尾使用&lt;cfdocumentsection&gt; 来定义页脚? &lt;cfdocumentsection&gt; 还允许您为该部分指定 marginBottomSee documentation here我将添加一个答案来说明我认为可能有效的方法。

标签: pdf coldfusion pdf-generation cfdocument


【解决方案1】:

我尚未对此进行测试,但它可能会起作用。使用&lt;cfdocumentsection&gt; 标签定义&lt;cfdocument&gt; 代码块的特定区域。 &lt;cfdocumentsection&gt; 还允许您仅为该部分指定 marginBottom。

According to the docs:

将 PDF 或 FlashPaper 文档分成多个部分。通过将此标记与cfdocumentitem 标记结合使用,每个部分都可以有唯一的页眉、页脚和页码。

试试这样的:

<cfdocument format="PDF" unit="in" ... >
    <cfdocumentsection>
        <!--- All of your existing logic here --->
    </cfdocumentsection>
    <cfdocumentsection marginbottom="1.5"> 
        <cfdocumentitem type="footer" evalAtPrint="true">
            <cfif cfdocument.currentPageNumber eq cfdocument.totalPageCount>
                This is the last page footer
            </cfif>
        </cfdocumentitem>
    </cfdocumentsection>
</cfdocument>

【讨论】:

  • 感谢您的回复@Miguel-F。我使用了上面的代码,但是页脚完全消失了。
  • @Sammy - 您可以尝试不使用&lt;cfif cfdocument.currentPageNumber ... 条件来显示页脚吗?换句话说,先尝试“正常”cfdocumentitem type="footer",看看会发生什么。
  • 不幸的是同样的结果
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-14
  • 2016-06-16
  • 2012-02-06
  • 2019-09-25
  • 2015-07-14
  • 1970-01-01
相关资源
最近更新 更多