<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The LiveCycle Post &#187; khsingh</title>
	<atom:link href="http://blogs.adobe.com/livecyclepost/author/khsingh/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.adobe.com/livecyclepost</link>
	<description>Hand-picked user assistance content from the LiveCycle community</description>
	<lastBuildDate>Tue, 23 Apr 2013 08:15:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Using LiveCycle to programmatically split the PDF documents – Part 1</title>
		<link>http://blogs.adobe.com/LiveCycleHelp/2012/11/using-livecycle-to-programmatically-split-the-pdf-documents-part-1.html</link>
		<comments>http://blogs.adobe.com/LiveCycleHelp/2012/11/using-livecycle-to-programmatically-split-the-pdf-documents-part-1.html#comments</comments>
		<pubDate>Fri, 02 Nov 2012 11:14:24 +0000</pubDate>
		<dc:creator>khsingh</dc:creator>
		
		<guid isPermaLink="false">http://blogs.adobe.com/LiveCycleHelp/?p=773</guid>
		<description><![CDATA[- Khushwant Singh, Content and Community Lead @ Adobe A discussion on Adobe forums indicates that a lot of LiveCycle users are trying to figure out how to&#160;programmatically&#160;split a PDF file. Adobe LiveCycle provides a simple method to&#160;programmatically&#160;split PDF documents &#8230; <a href="http://blogs.adobe.com/LiveCycleHelp/2012/11/using-livecycle-to-programmatically-split-the-pdf-documents-part-1.html">Continue reading <span>&#8594;</span></a>
]]></description>
				<content:encoded><![CDATA[<p><em><strong>- <a title="Khushwant Sehgal" href="http://blogs.adobe.com/khushwantsehgal" >Khushwant Singh</a></strong></em>, Content and Community Lead @ Adobe</p>
<p>A discussion on Adobe forums indicates that a lot of LiveCycle users are trying to figure out how to programmatically split a PDF file. Adobe LiveCycle provides a simple method to programmatically split PDF documents using LiveCycle Assembler service. You can split PDF files using the bookmark tags or by page number.</p>
<p>To split the PDF documents, you require:</p>
<ul>
<li>A DDX (For more information about DDX, see Adobe LiveCycle <a title="DDX Reference Guide" href="http://help.adobe.com/en_US/livecycle/10.0/ddxRef.pdf" >DDX reference guide</a>)</li>
<li>Source documents</li>
<li>Access to the running instance of Adobe LiveCycle</li>
</ul>
<p>You can write a custom DDX document suited to your requirements.  Some of the most commonly requested DDX are:</p>
<p><strong>DDX for splitting PDF document </strong><strong>using bookmarks</strong></p>
<p>In the following sample DDX<em>, </em>LiveCycle Assembler service<em> </em>generates a single document for each level 1 bookmark in the source document (AssemblerResultPDF.pdf in this example). The Assembler service generates a name for each document that is the concatenation of the following items:</p>
<ul>
<li>A string specified by the prefix attribute</li>
<li>A 6-digit sequence number (This number could be used to re-create the original order of the pages after the document is disassembled.)</li>
<li>The bookmark title</li>
<li>The filename extension .pdf</li>
</ul>
<p><code>&lt;PDFsFromBookmarks prefix="stmt"&gt;<br />
&lt;PDF source="doc1.pdf"/&gt;<br />
&lt;/PDFsFromBookmarks&gt;</code></p>
<p><strong>DDX for splitting PDF document using page numbers</strong></p>
<p>In this sample DDX<em>, </em>LiveCycle Assembler service<em> </em>generates documents for the mentioned page number from the source document. The Assembler service generates a name for each document based on the result parameter specified in the DDX.<strong></strong><br />
<code><br />
&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;DDX xmlns="http://ns.adobe.com/DDX/1.0/"&gt;<br />
&lt;PDF result="Final.pdf"&gt;<br />
&lt;PDF source="PDF1.pdf" pages="1"/&gt;<br />
&lt;/PDF&gt;<br />
&lt;PDF result="Final2.pdf"&gt;<br />
&lt;PDF source="PDF1.pdf" pages="2"/&gt;<br />
&lt;/PDF&gt;<br />
&lt;/DDX&gt;<br />
</code><br />
<strong>DDX for splitting PDF document using the page range</strong></p>
<p>In this sample DDX<em>, </em>LiveCycle Assembler service<em> </em>generates documents for the mentioned range of the pages. The Assembler service generates a name for each document based on the result parameter specified in the DDX.<strong></strong><br />
<code><br />
&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;DDX xmlns="http://ns.adobe.com/DDX/1.0/"&gt;<br />
&lt;PDF result="Final.pdf"&gt;<br />
&lt;PDF source="PDF1.pdf" pages="1-5"/&gt;<br />
&lt;/PDF&gt;<br />
&lt;/DDX&gt;<br />
</code><br />
<strong>DDX for splitting PDF documents using page range from different PDF documents and creating a single resultant PDF document</strong></p>
<p>In the following sample DDX<em>, </em>LiveCycle Assembler service<em> </em>extracts pages from multiple documents as per the range of pages mentioned in the DDX and generates a single output document<br />
<code><br />
&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;DDX xmlns="http://ns.adobe.com/DDX/1.0/"&gt;<br />
&lt;PDF result="Final.pdf"&gt;<br />
&lt;PDF source="PDF1.pdf" pages="1-3"/&gt;<br />
&lt;PDF source="PDF2.pdf" pages="4-5"/&gt;<br />
&lt;/PDF&gt;<br />
&lt;/DDX&gt;<br />
</code><br />
<strong>Sample program to split a PDF document</strong><br />
Let us write a simple Java program to split a PDF document into multiple documents.   To download the resources used in this sample program, <a href="http://blogs.adobe.com/khushwantsehgal/files/2012/11/resources.zip" >click here</a>.</p>
<p>Complete the following steps:</p>
<ol>
<li>Create a new file and add the following code  to the file<code><br />
&lt;DDX xmlns="http://ns.adobe.com/DDX/1.0/"&gt;<br />
&lt;PDFsFromBookmarks prefix="Readme"&gt;<br />
&lt;PDF source="AssemblerResultPDF.pdf"/&gt;<br />
&lt;/PDFsFromBookmarks&gt;<br />
&lt;/DDX&gt;</code><br />
For this example, save the XML file as <em>shell_disassemble.xml</em>.</li>
<li>Create a new Java project and add shell_disassemble.xml to the project.</li>
<li>Add the following libraries to your project. These libraries are required to invoke assembler service in SOAP mode:
<ul>
<li><em>adobe-assembler-client.jar</em></li>
<li><em>adobe-livecycle-client.jar</em></li>
<li><em>adobe-usermanager-client.jar</em></li>
<li><em>adobe-utilities.jar</em></li>
<li><em>jbossall-client.jar (use a different JAR file if LiveCycle ES is not deployed on JBoss)</em></li>
<li><em>activation.jar</em></li>
<li><em>axis.jar</em></li>
<li><em>commons-codec-..jar</em></li>
<li><em>commons-collections-..jar</em></li>
<li><em>commons-discovery.jar</em></li>
<li><em>commons-logging.jar</em></li>
<li><em>dom-xml-apis-.jar</em></li>
<li><em>jaxen-.-beta-jar</em></li>
<li><em>jaxrpc.jar</em></li>
<li><em>log4j.jar</em></li>
<li><em>mail.jar</em></li>
<li><em>saaj.jar</em></li>
<li><em>wsdl4j.jar</em></li>
<li><em>xalan.jar<br />
</em></li>
<li><em>xbean.jar</em></li>
<li><em>xercesImpl.jar</em></li>
</ul>
</li>
<li>Create a new class named <em>DisassemblePDFSOAP</em> .</li>
<li>Add the source PDF file to the project. I have used AssemblerResultPDF.pdf</li>
<li>Add following code to the class:<br />
<em>import com.adobe.livecycle.assembler.client.*;</em><br />
<em>import java.util.*;</em><br />
<em>import java.io.InputStream;</em><br />
<em>import java.io.*;</em><br />
<em>import com.adobe.idp.Document;</em><br />
<em>import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;</em><br />
<em>import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties;</em><br />
<em>public class DisassemblePDFSOAP</em><br />
<em>{</em><br />
<em>public static void main (String args[]) {</em><br />
<em>Document outDoc = null;</em><br />
<em>try{</em><br />
<em>//Set connection properties required to invoke LiveCycle ES2</em><br />
<em>Properties connectionProps = new Properties();</em><br />
<em>connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT, &#8220;http://10.40.18.95:8080&#8243;);</em><br />
<em>connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,ServiceClientFactoryProperties.DSC_SOAP_PROTOCOL);</em><br />
<em>connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, &#8220;JBoss&#8221;);</em><br />
<em>connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, &#8220;administrator&#8221;);</em><br />
<em>connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, &#8220;password&#8221;);</em><em>//Create a ServiceClientFactory instance</em><br />
<em>ServiceClientFactory myFactory = ServiceClientFactory.createInstance(connectionProps);</em><em>//Create an AssemblerServiceClient object</em><br />
<em>AssemblerServiceClient assemblerClient = new AssemblerServiceClient(myFactory);</em><em>FileInputStream myDDXFile = new FileInputStream(&#8220;E:\\workspace\\disassemble\\src\\shell_disassemble.xml&#8221;);</em><br />
<em>//Create a Document object based on the DDX file</em><br />
<em>Document myDDX = new Document(myDDXFile);</em><em>//Create a Map object to store PDF source documents</em><br />
<em>Map inputs = new HashMap();</em><em>FileInputStream mySourceMap = new FileInputStream(&#8220;E:\\workspace\\backup\\disassemble\\src\\AssemblerResultPDF.pdf&#8221;);</em><em>//Create a Document object based on the map.pdf source file</em><br />
<em>Document myPDFSource = new Document(mySourceMap);</em><em>//Place two entries into the Map object</em><br />
<em>inputs.put(&#8220;AssemblerResultPDF.pdf&#8221;,myPDFSource);</em><em>//Create an AssemblerOptionsSpec object</em><br />
<em>AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec();</em><br />
<em>assemblerSpec.setFailOnError(false);</em><em>//Submit the job to the Assembler service</em><br />
<em>AssemblerResult jobResult = assemblerClient.invokeDDX(myDDX,inputs,assemblerSpec);</em><br />
<em>java.util.Map allDocs = jobResult.getDocuments();</em></p>
<p><em>//Retrieve the result PDF documents from the Map object</em></p>
<p><em>int index = 0;</em></p>
<p><em>//Iterate through the map object to retrieve the result PDF document</em><br />
<em>for (Iterator i = allDocs.entrySet().iterator(); i.hasNext();) {</em><br />
<em>// Retrieve the Map object&#8217;s value</em></p>
<p><em>Map.Entry e = (Map.Entry)i.next();</em><br />
<em>if (index == 0)</em><br />
<em>{</em><br />
<em>Object o = e.getValue();</em></p>
<p><em>//Cast the Object to a Document</em><br />
<em>//and save to a file</em><br />
<em>outDoc = (Document)o;</em><br />
<em>File myOutFile = new File(&#8220;E:\\disassemble\\SplitPDF&#8221;+index +&#8221;.pdf&#8221;);</em><br />
<em>outDoc.copyToFile(myOutFile);</em><br />
<em>}</em><br />
<em>index++;</em><br />
<em>}</em><br />
<em>if (index &gt; 0)</em><br />
<em>System.out.println(&#8220;The PDF document was disassembled into &#8220;+index+&#8221; PDF documents.&#8221;);</em><br />
<em>else</em><br />
<em>System.out.println(&#8220;The PDF document was not disassembled.&#8221;);</em></p>
<p><em>}catch (Exception e) {</em><br />
<em>System.out.println(&#8220;Error OCCURRED: &#8220;+e.getMessage());</em><br />
<em>e.printStackTrace();</em><br />
<em>}</em><br />
<em>}</em><br />
<em>}</em></li>
<li>Modify the locations mentioned in the sample code according to the file paths in your machine</li>
<li>Run the code.</li>
<li>The code splits the file into multiple PDF documents based on the bookmarks or the page numbers specified in the DDX.</li>
</ol>
<p>This is first blog in the series of the blogs about programmatically splitting the PDF document. In this blog I have shared sample code to split <strong>PDF document using bookmarks</strong>. In the follow-up blogs, I will include sample code to split PDF documents using:</p>
<ul>
<li>Page numbers</li>
<li>Page range</li>
<li>Pages from different PDF documents and generate a single output document</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/livecyclepost/2012/11/using-livecycle-to-programmatically-split-the-pdf-documents-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
	</channel>
</rss>
