coldfusion/DDX PDF 单页书签
coldfusion/DDX PDF single page bookmarks
是否可以在不开始新页面的情况下使用 Coldfusion 或 DDX 生成书签(对于内容的 DDX table)?
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 文档
在您的 <cfdocument>
标签中尝试添加 bookmark
属性以在 PDF 中启用书签。像这样:
<cfdocument name="myPdf" format="PDF" bookmark="yes">
...
注意: ColdFusion 9 中添加了对此的支持。你没有提到你是什么版本 运行。
Bookmarks
ColdFusion 9 supports bookmarks. In the cfdocument tag, set the bookmark attribute to yes. Then specify the bookmark name for each cfdocumentsection tag.
我找到了解决方案,但这并不容易:
假设我们有 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)>
为 DDX 操作定义 bookmark.xml
<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>
是否可以在不开始新页面的情况下使用 Coldfusion 或 DDX 生成书签(对于内容的 DDX table)?
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 文档
在您的 <cfdocument>
标签中尝试添加 bookmark
属性以在 PDF 中启用书签。像这样:
<cfdocument name="myPdf" format="PDF" bookmark="yes">
...
注意: ColdFusion 9 中添加了对此的支持。你没有提到你是什么版本 运行。
Bookmarks
ColdFusion 9 supports bookmarks. In the cfdocument tag, set the bookmark attribute to yes. Then specify the bookmark name for each cfdocumentsection tag.
我找到了解决方案,但这并不容易:
假设我们有 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)>
为 DDX 操作定义 bookmark.xml
<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>