Wednesday, June 27, 2007

cfpdf - action = merge

 
Hi,
   I thought I did post some usage examples for the cfpdf tag.
 
Suppose I have a pdf file of 100 pages, and I want only the selected pages in a separate pdf.
I want only the 7, 10, 15, 20, 25, 40 pages, here is how to acheive this.
 
<cfset sourcefile = ExpandPath('inputfiles\merge_test1.pdf')>
<cfset destinationfile= ExpandPath('results\merge_result1.pdf')>
 
<cfpdf action=merge source="#sourcefile#" Pages="7, 10, 15, 20, 25, 40" destination="#destinationfile#" overwrite="true">
 
Now suppose I want just the first 3 chapters of the entire pdf file, I can specify the page numbers in a block.
Assuming that the first 3 chapters are in the first 30 pages, here is how to acheive that.
 
<cfpdf action=merge source="#sourcefile#" Pages="1-30" destination="#destinationfile#" overwrite="true">
 
Supposedly, I wanted just the first chapter(10 Pages) and the 5th Chapter(50-60 Pages)...
 
<cfpdf action=merge source="#sourcefile#" Pages="1-10, 50-60" destination="#destinationfile#" overwrite="true">
 
In case you wanted some specific pages along with a block of pages to be merged... 
 
<cfpdf action=merge source="#sourcefile#" Pages="1-10, 21, 31, 41, 50-60" destination="#destinationfile#" overwrite="true">
 
Now, if your source file is password protected, you can provide the password in the cfpdf tag.
 
<cfpdf action=merge source="#sourcefile#" Pages="5, 9, 16, 18" password="mypwd" destination="#destinationfile#" overwrite="true">
 
If we have a set of pdf files in a directory and we want to merge all of the pdf files into a single one,
 
<cfset sourcedir = ExpandPath('inputfiles\mergetest-dir')>
<cfset destinationfile = ExpandPath('results\merge_result_dir.pdf')>
 
<cfpdf action=merge directory="#sourcedir#" destination="#destinationfile#" overwrite="true">
 
In the above action, the files might be merged in any order, suppose I wanted it to merge by the name of the file,
 
<cfpdf action=merge directory="#sourcedir#" destination="#destinationfile#" order="name" overwrite="true">
 
And another attribute to help you sort in the way you want(asc or desc)
 
<cfpdf action=merge directory="#sourcedir#" destination="#destinationfile#" order="name" ascending="false" overwrite="true">
<cfpdf action=merge directory="#sourcedir#" destination="#destinationfile#" order="name" ascending="true" overwrite="true">
 
We can also have the merged pdf as a variable
 
<cfpdf action=merge source="#sourcefile#" Pages="7, 10, 11" name="pagedata">
 
We can perform actions on the variable 'pagedata'
 
<cfpdf action=getinfo source="pagedata" name="myVar">
<cfoutput>The total number of pages = #myVar.TotalPages#</cfoutput><br><br>
 
If you are merging a set of pdf files/pages, and you want to keep your bookmark,
 
<cfpdf action=merge source="#sourcefile#" Pages="7, 10, 11" destination="#destinationfile#" overwrite="true" keepbookmark="true">
 
 
Merging diff pages from different pdf's
 
Now you need to merge a set of pages from different pdf files,
 
<cfset sourcefile1 = ExpandPath('inputfiles\test1.pdf')>
<cfset sourcefile2 = ExpandPath('inputfiles\test2.pdf')>
<cfset sourcefile3 = ExpandPath('inputfiles\test3.pdf')>
 
<cfset destinationfile = ExpandPath('results\result1.pdf')>
 
<cfpdf action="merge" destination="#destinationfile#" overwrite="true">
         <cfpdfparam source="#sourcefile1#" pages="1-3, 5">
         <cfpdfparam source="#sourcefile2#"><!--- entire pdf here --->
         <cfpdfparam source="#sourcefile3#" pages="2" password="cfpdfparam_test3" >
</cfpdf>
 

7 comments:

Anonymous said...

awesome post!!! thanks!

Anonymous said...

Is there a way to redo the page numbers in footers (for ex.) after a merge?

Javi said...

Ahamad,

I had commented on another post but I see here you have something on merging. Is it possible to merged several populated dynamic PDF's and not lose the populated data in those PDF's in the final merged file?

At work I'm creating a service to handle this for us. So far its worked great except on the last portion when merging. I'm worried that we can't take our dynamic PDF's built with LiveCycle Designer, populate individual ones and then merge them together still containing that populated data.

Ahamad said...

@Javi,
Please try the following:
1. Fill the forms using cfpdfform.
2. Flatten the filled up forms using cfpdf write, flatten=true.
3. Merge the flattened forms usinf cfpdf merge.

It is difficult to post code in the comments for blogger. I will post a separate blog entry with the source code.

Ahamad said...

I have added a new post and example code, Please check - http://cfpdf.blogspot.com/2008/04/populate-and-merge-multiple-pdf-forms.html

Kamagra 100mg said...

Nice Post Love Reading Its

generic Viagra

silagra pills

Unknown said...
This comment has been removed by the author.