Using DDX instructions to create a book

The following example shows how to create a book using DDX instructions with the processddx action. Specifically, it shows how to perform the following tasks:

  • Merge several PDF documents into an output file.

  • Add a generated table of contents page.

  • Add headers and footers.

  • Add automatic page numbers.

  • Apply different styles to the table of contents and the body of the book.

The following code shows the DDX file:

<?xml version="1.0" encoding="UTF-8"?> 
<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="Doc0"/> 
<TableOfContents maxBookmarkLevel="3" bookmarkTitle="Table of Contents" 
    includeInTOC="false"> 
        <Header styleReference="TOCheaderStyle"/> 
        <Footer styleReference="TOCFooterStyle"/> 
    </TableOfContents> 
    <PDFGroup> 
        <Footer styleReference="FooterStyle"/> 
        <PDF source="Doc1"/> 
        <PDF source="Doc2"/> 
        <PDF source="Doc3"/> 
        <PDF source="Doc4"/> 
    </PDFGroup> 
    </PDF> 
 
    <StyleProfile name="TOCheaderStyle"> 
    <Header> 
        <Center> 
            <StyledText> 
            <p color="red" font-weight="bold" font="Arial">Table of Contents</p> 
            </StyledText> 
        </Center> 
    </Header> 
    </StyleProfile> 
 
    <StyleProfile name="TOCFooterStyle"> 
    <Footer> 
        <Right> 
            <StyledText> 
            <p font-size="9pt">Page <_PageNumber/> of <_LastPageNumber/></p> 
            </StyledText> 
        </Right> 
    </Footer> 
    </StyleProfile> 
     
    <StyleProfile name="FooterStyle"> 
    <Footer> 
        <Left> 
            <StyledText> 
            <p font-size="9pt"><i>CFML Reference</i></p> 
            </StyledText> 
        </Left> 
        <Right> 
            <StyledText> 
            <p font-size="9pt">Page <_PageNumber/> of <_LastPageNumber/></p> 
            </StyledText> 
        </Right> 
    </Footer> 
    </StyleProfile> 
 
</DDX>

The following code shows the ColdFusion page that processes the DDX instructions:

<cfif IsDDX("Book.ddx")> 
    <cfset inputStruct=StructNew()> 
    <cfset inputStruct.Doc0="Title.pdf"> 
    <cfset inputStruct.Doc1="Chap1.pdf"> 
    <cfset inputStruct.Doc2="Chap2.pdf"> 
    <cfset inputStruct.Doc3="Chap3.pdf"> 
    <cfset inputStruct.Doc4="Chap4.pdf"> 
 
    <cfset outputStruct=StructNew()> 
    <cfset outputStruct.Out1="myBook.pdf"> 
 
    <cfpdf action="processddx" ddxfile="book.ddx" inputfiles="#inputStruct#"  
        outputfiles="#outputStruct#" name="ddxVar"> 
 
    <cfoutput>#ddxVar.Out1#</cfoutput> 
</cfif>