pdf - Coldfusion/DDX PDF 单页书签

标签 pdf coldfusion cfml ddx

是否可以使用 Coldfusion 或 DDX 生成书签(用于 DDX 目录)而无需开始新页面?

Coldfusion 使我们能够通过以下方式生成 pdf 书签:

<cfdocumentsection name=""></cfdocumentsection>

但这也会创建一个新页面。

欢迎所有帮助。

代码:

<cfdocument name="myPdf" format="PDF">
    <cfdocumentsection name="section 1">
        This is section 1
    </cfdocumentsection>
    <cfdocumentsection name="section 2">
        This is section 2
    </cfdocumentsection>
    <cfdocumentsection name="section 3">
        This is section 3
    </cfdocumentsection>
</cfdocument>
<cfprocessingdirective suppressWhitespace="true">
        <cfcontent type="application/pdf" reset="true" variable="#tobinary(myPdf)#"/>
</cfprocessingdirective>

这会生成一个包含 3 页和 3 个书签的 pdf 文档

最佳答案

我找到了解决方案,但这并不容易:

假设我们有 3 个长度未定义的部分

    <cfsavecontent variable="section1">
        <p>This is section 1</p>
    </cfsavecontent>
    <cfsavecontent variable="section2">
        <p>This is section 2</p>
    </cfsavecontent>
    <cfsavecontent variable="section3">
        <p>This is section 3</p>
    </cfsavecontent>

<cfset sectionList = 'section1,section2,section3'>
<cfset bookmarkList = "">
<cfset content = "">
<cfset currentPage = 1>
<cfloop list="#sectionList#" index="i">
    <cfdocument name="infoPdf" format="PDF" bookmark="false">
        <cfdocumentsection>
            <cfoutput>#content#</cfoutput>
            <h2>FakeHeader</h2>
        </cfdocumentsection>
    </cfdocument>

获取页面信息以了解内容将在哪个页面

        <cfpdf action="getinfo" name="pdfInfo" source="infoPdf">
        <cfset currentPage = pdfInfo.TotalPages>
        <cfset bookmarkList = listAppend(bookmarkList, currentPage)> 
        <cfset content &= VARIABLES[i]> 
        <cfdocument name="myPdf" format="PDF" bookmark="false">
            <cfdocumentsection>
                <cfoutput>#content#</cfoutput>
            </cfdocumentsection>
        </cfdocument>
    </cfloop>
    <cfset fileWrite(ExpandPath("test.pdf"),myPdf)>

定义 bookmark.xml 以进行 DDX 操作

<cfxml variable="bookmarks">
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Bookmarks xmlns="http://ns.adobe.com/pdf/bookmarks" version="1.0">
    <cfoutput>
        <cfloop from="1" to="#listlen(sectionList)#" index="i">
            <Bookmark>
                <Title>#ListGetAt(sectionList,i)#</Title>
                <Dest>
                  <Fit PageNum="#ListGetAt(bookmarkList,i)-1#"/>
                </Dest>
            </Bookmark>  
        </cfloop>
    </cfoutput>
</Bookmarks>
</cfxml>
<cfset fileWrite(ExpandPath("/bookmarks.xml"),bookmarks)>

DDX 文件

<cfsavecontent variable="myDDX">
    <DDX xmlns="http://ns.adobe.com/DDX/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ns.adobe.com/DDX/1.0/ coldfusion_ddx.xsd">
        <PDF result="Out1">
            <PDF source="test"/>
            <Bookmarks source="inputxml"/>
        </PDF>
        <PDF result="Out">
            <TableOfContents includeInTOC="false" bookmarkTitle="Table of Contents"  maxBookmarkLevel="infinite">   
                <TableOfContentsEntryPattern applicableLevel="all">
                    <StyledText>
                        <p font-family="Arial" font-size="11pt">
                            <_BookmarkTitle/>
                            <Space/>
                            <Space/>
                            <leader leader-pattern="dotted"/>
                            <Space/>
                            <Space/> 
                            <_BookmarkPageCitation/>
                        </p>
                    </StyledText>
                </TableOfContentsEntryPattern>
            </TableOfContents>
            <PDF source="Out1"/>
        </PDF>
    </DDX>
</cfsavecontent>

DDX处理

    <cfset inputStruct = StructNew()>
    <cfset inputStruct.test = 'test.pdf'>
    <cfset inputStruct.inputxml = "bookmarks.xml"/>
    <cfset outputStruct = StructNew()>
    <cfset outputStruct.Out = "CombinedDocument.pdf">
<cfpdf action="processddx" ddxfile="#myddx#" inputfiles="#inputStruct#" outputfiles="#outputStruct#" name="ddxVar">
<cfpdf action="read" source="CombinedDocument.pdf" name="resultPdf">
<cfprocessingdirective suppressWhitespace="true">
    <cfcontent type="application/pdf" reset="true" variable="#tobinary(resultPdf)#"/>
</cfprocessingdirective> 

关于pdf - Coldfusion/DDX PDF 单页书签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37346831/

相关文章:

java - Cfscript 和动态值

arrays - ArraySort 回调未按正确顺序对我的数组进行排序

java - Android 应用程序中的自定义 PDF 查看器,需要免费或一次性许可的解决方案

c# - 使用 docraptor c# 在 PDF 中添加页眉和页脚图像

asp.net - 在coldfusion 和.net 上单点登录

forms - 为什么 ColdFusion 认为值 "7+"是一个有效的整数值,我如何验证它不是?

pdf - 导入 *.pdf_tex 文件错误

r - 使用 R Markdown 在 PDF 中缩进第一行段落

session - 如何在 session 结束时运行查询?

coldfusion - 在冷融合中使用动态案例切换(真)?