在CF中生成多个PDF时出错

时间:2014-09-17 02:38:03

标签: coldfusion pdf-generation coldfusion-9

我在制作多页PDF时遇到错误。

未在cfpdf标记中为MERGE操作指定pages属性。

导致此问题的行是:<cfpdf action="merge" source="#ArrayToList(variables.pdfList)#" destination="promega.pdf" overwrite="yes" />

我尝试查看Adobe的文档错误,无法找到合并操作的属性pages。想法?

                                              

        <!--- Append PDF to list for merge printing later --->
        <cfset ArrayAppend(variables.pdfList, "#expandPath('.')#\general.pdf") />

        <cfset variables.userAgenda = GetAttendeeSchedule(
            variables.event_key,
            variables.badgeNum
        ) />


        <!--- Field CFID is the id of the agenda item; use this for certificate selection --->
        <cfif variables.userAgenda.recordcount>
            <cfloop query="variables.userAgenda">
                <cfset variables.title = Trim(variables.userAgenda.CUSTOMFIELDNAMEONFORM) />

                <cfpdfform source="#expandPath('.')#\promega_certificate.pdf" destination="#cfid#.pdf" action="populate">

                        <cfset variables.startdate = replace(CUSTOMFIELDSTARTDATE, "T", " ") />

                        <cfpdfformparam name="WORKSHOP" value="#variables.title#">
                        <cfpdfformparam name="NAME" value="#variables.badgeInfo.FirstName# #variables.badgeInfo.LastName#">
                        <cfpdfformparam name="STARTDATE" value="#DateFormat(variables.startdate, "medium" )#">

                </cfpdfform>

                <!--- Append PDF to list for merge printing later --->
                <cfset ArrayAppend(variables.pdfList, "#expandPath('.')#\#cfid#.pdf") />
            </cfloop>
        </cfif>

        <cfif ArrayLen(variables.pdfList)>
            <cfpdf action="merge" source="#ArrayToList(variables.pdfList)#" destination="promega.pdf" overwrite="yes" />
            <!--- Delete individual files --->
            <cfloop list="#ArrayToList(variables.pdfList)#" index='i'>
                <cffile action="delete" file="#i#" />
            </cfloop>
            <cftry>
                <cffile action="delete" file="#expandPath('.')#\general.pdf" />
                <cfcatch></cfcatch>
            </cftry>
            <cfheader name="Content-Disposition" value="attachment;filename=promega.pdf">
            <cfcontent type="application/octet-stream" file="#expandPath('.')#\promega.pdf" deletefile="Yes">

            <cflocation url="index.cfm" addtoken="false" />
        </cfif>

2 个答案:

答案 0 :(得分:2)

当source是单个文件而不是以逗号分隔的文件列表时,会发生这种情况。我猜测,如果它是单个文件,则期望提取一些页面而不是添加。

答案 1 :(得分:0)

我在我的coldfusion 9机器上尝试了以下操作,它运行得很好:

<cfset strPath = GetDirectoryFromPath(GetCurrentTemplatePath()) />
<Cfset pdflist = arrayNew(1)>
<Cfset pdflist[1] = "#strPath#page1.pdf">
<Cfset pdflist[2] = "#strPath#page2.pdf">

<cfpdf action="merge" source="#ArrayToList(pdflist)#" destination="#strPath#merged.pdf" overwrite="yes" />

您可以尝试合并这样的页面并检查是否仍然出现错误:

<cfset strPath = GetDirectoryFromPath(GetCurrentTemplatePath()) />
<Cfset pdflist = arrayNew(1)>
<Cfset pdflist[1] = "#strPath#page1.pdf">
<Cfset pdflist[2] = "#strPath#page2.pdf">

<cfpdf action="merge" destination="#strPath#merged.pdf" overwrite="yes">
    <Cfloop from=1 to="#arraylen(pdflist)#" index="x">
    <cfpdfparam source="#pdfList[x]#">
    </cfloop>
</cfpdf>