【问题标题】:Can I include another PDF in CFDOCUMENT?我可以在 CFDOCUMENT 中包含另一个 PDF 吗?
【发布时间】:2013-09-28 16:51:44
【问题描述】:

我有一个在 Coldfusion 中生成的 PDF。我想从文件夹中的另一个 PDF 添加页面。 我已经检查了 cfpdf,但它似乎不是要走的路。 有没有办法做到这一点?

<cfdocument format="PDF" fontEmbed = "yes" pageType="A4" margintop="0.2" marginbottom="0.1" marginleft="0.2" marginright="0.2">
        <cfinclude template="header.inc">
        ... content ....
        pages 2nd PDF should be here
</cfdocument>

【问题讨论】:

    标签: pdf coldfusion coldfusion-9


    【解决方案1】:

    这里最简单的形式是如何将磁盘上现有的 PDF 附加到动态创建的 PDF 中,并将其提供给浏览器,而无需向物理或虚拟文件系统写入任何新内容。

    <!--- Create a new PDF and store it in a variable called newPdf --->
    <cfdocument format="PDF" name="newPdf">
      Content of new PDF here. Content of an existing PDF to be appended below.
    </cfdocument>
    
    <!--- Append to the new PDF the contents of the existing PDF located in the same folder as this script and store it in a variable called mergedPdf --->
    <cfpdf action="merge" name="mergedPdf">
        <cfpdfparam source="newPdf">
        <cfpdfparam source="existing.pdf">
    </cfpdf>
    
    <!--- Output the merged PDF to the browser --->
    <cfcontent type="application/pdf" variable="#ToBinary( mergedPdf )#" reset="true">
    

    (您可能需要添加&lt;cfheader&gt; 来建议浏览器应如何处理PDF,即inlineattachment。)

    【讨论】:

    • 用 Adob​​e CF9.0.1 测试
    【解决方案2】:

    【讨论】:

    • 我做到了,但是在我当前的设置中,PDF 文档是在单击链接后生成并立即提供给用户的,而 CFPDF 仅保存到磁盘,对吧?
    • 你当然可以,在链接请求中,仍然将你的cfdocument pdf写入磁盘,最好使用getTempDirectory(),然后使用cfpdf action="merge",然后将pdf直接渲染到浏览器使用 cfheader 和 cfcontent。
    猜你喜欢
    • 2011-03-31
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-20
    • 2014-01-18
    相关资源
    最近更新 更多