Thursday, July 5, 2007

Split a pdf file into multiple pdf docs

Hi,
 
Now suppose, you need to split a huge pdf file into multiple pdf docs.
 
Here is how you can acheive this using ddx.

===============================
 
<cfset sourcefile1 = ExpandPath('test.pdf')>
 
<cfset inputStruct=StructNew()>
<cfset inputStruct.Doc1="#sourcefile1#">
 
<cfpdf action="getinfo" source="#sourcefile1#" name="fullPdf">
<cfoutput>TotalPages is #fullPdf.TotalPages#</cfoutput><br>
 
<cfset totalpages = "#fullPdf.TotalPages#">
 
<cfset outputStruct=StructNew()>
 
<cfloop index="i" from="1" to="#totalpages#">
 <cfset fileStr = 'test_part' & '#i#' & '.pdf'>
 <cfset "destinationfile#i#" = ExpandPath('#fileStr#')>
 <cfset "outputStruct.OUT#i#" = "#Evaluate('destinationfile#i#')#">
</cfloop>
 
<cfset ddx_part1 = '<?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">'> 
 
<cfset ddx_part2 = "">
 
<cfloop index="i" from="1" to="#totalpages#"> 
  <cfset ddx_part2 = ddx_part2 & '<PDF result="Out#i#"><PDF source="Doc1" pages="#i#"/></PDF>'>
</cfloop>
 
<cfset ddx_part3 = '</DDX>'>
 
<cfset myVar = ddx_part1 & ddx_part2 & ddx_part3>
 
<cfpdf action="processddx" ddxfile="#myVar#" inputfiles="#inputStruct#" outputfiles="#outputStruct#" name="ddxVar">
 
<cfoutput>#ddxVar.Out1#</cfoutput>
<br><br>
===============================
 
 

6 comments:

Anonymous said...

Interesting but could not also just do this?

cfset sourcefile1 = ExpandPath('test.pdf')>
cfpdf action="getinfo" source="#sourcefile1#" name="fullPdf">

cfset totalpages = fullPdf.TotalPages>

cfloop index="i" from="1" to="#totalpages#">
cfpdf action="merge" source="#sourcefile1#" pages="#i#" destination="#ExpandPath('testPage#i#.pdf')#>
/cfloop>

(blogger does not allow an opening tag in comments...)

Ahamad said...

Correct... You can achieve the same by either ways.

Anonymous said...

Hi. Is it possible to only extract the bookmarks out of a very huge pdf file? It takes forever if you get the whole xml...

Ahamad said...

No, it is not possible to extract the bookmarks.

PaulaSchmitt said...

hello guys

forgive the ignorance but all those letters looked like chinese to me. i wonder if there is any way, without having to purchase a software, to split my pdf doc into separate pdf files (i want to post an article i wrote on my blog, but my editor sent me one single file with eight pages of rolling stone magazine - pages are huge - too big for blogger). any help is most welcome, just bear in mind that i am over dumb when it comes to html language. thank you much. cheers
p

Ahamad said...

Hi Paula,
You can acheive splitting of huge pdf doc into smaller pdf's using ColdFusion8. I can help you out. Let me know your problem.

-ahamad