ColdFusion lets you merge PDF documents in the following ways:
To merge the contents of a directory, use the merge action and specify the directory where the source PDF files are located, as the following example shows:
<cfpdf action="merge" directory="c:/BookFiles" destination="myBook.pdf" overwrite="yes">
By default, ColdFusion merges the source files in descending order by timestamp. You can control the order in which the PDF files are added to the book by setting the order and ascending attributes. The following code merges the files in ascending order according to the timestamp on the files:
<cfpdf action="merge" directory="c:/BookFiles" destination="myBook.pdf" order="name" ascending="yes" overwrite="yes">
By default, ColdFusion continues the merge process even if it encounters a file that is not a valid PDF document in the specified directory. To override this setting, set the stopOnError attribute to yes, as the following example shows:
<cfpdf action="merge" directory="c:/BookFiles" destination="myBook.pdf" order="time" ascending="yes" overwrite="yes" stopOnError="yes">
You can merge a comma-separated list of PDF files. To do this, you must specify the absolute pathname for each file, as the following example shows:
<cfpdf action="merge" source="c:\coldfusion\wwwroot\lion\Chap1.pdf,c:\coldfusion\wwwroot\lion\Chap2.pdf" destination="twoChaps.pdf" overwrite="yes">
For more control over which files are added to the merged document, use the cfpdfparam tag with the cfpdf tag. The cfpdfparam tag merges documents or pages from documents located in different directories into a single output file. When you use the cfpdfparam tag, the PDF files are added to the output file in the order they appear in the code. In the following example, the cover, title, and copyright pages are followed by the first five pages of the introduction, then all of the pages in Chapter 1, and then the first page followed by pages 80-95 in Chapter 2:
<!--- Use the cfdocument tag to create PDF content and write the output to a variable called coverPage. ---> <cfdocument format="PDF" name="coverPage"> <html> <body> <h1>Cover page</h1> <p>Please review the enclosed document for technical accuracy and completeness.</p> </body> </html> </cfdocument> <!--- Use the cfpdf tag to merge the cover page generated in ColdFusion with pages from PDF files in different locations. ---> <cfpdf action="merge" destination="myBook.pdf" overwrite="yes" keepBookmark="yes"> <cfpdfparam source="coverPage"> <cfpdfparam source="title.pdf"> <cfpdfparam source="e:\legal\copyright.pdf"> <cfpdfparam source="boilerplate\intro.pdf" pages="1-5"> <cfpdfparam source="bookfiles\chap1.pdf"> <cfpdfparam source="bookfiles\chap2.pdf" pages="1,80-95"> </cfpdf>
Because the keepbookmark attribute is set to yes, ColdFusion retains the bookmarks from the source documents in the output file.