|
|
The following C# .NET code example merges two PDF source documents (map.pdf and directions.pdf) into a single PDF document.using System;using System.Collections;using System.ComponentModel;using System.Data;using System.IO ;namespace AssemblerWSApp{class AssemblerTest{[STAThread]static void Main(string[] args){try{// Create a AssemblerServiceService objectAssemblerServiceService asOb = new AssemblerServiceService();// Provide authentication credentials to the serviceasOb.Credentials = new System.Net.NetworkCredential("administrator","password");// Create BLOBs that represents the input DDX file and PDF sourcesBLOB ddxDoc = new BLOB();BLOB mapDoc = new BLOB();BLOB optionsDoc = new BLOB();// Get the input DDX document and input PDF sourcesstring ddxFileName = "C:\\shell.xml";FileStream ddxFs = new FileStream(ddxFileName, FileMode.Open);string pdfFileNameMap = "C:\\map.pdf";FileStream mapFs = new FileStream(pdfFileNameMap, FileMode.Open);string pdfFileNameOptions = "C:\\directions.pdf";FileStream optionsFs = new FileStream(pdfFileNameOptions, FileMode.Open);// Get the lengths of the file streams and create byte arraysint ddxLen = (int)ddxFs.Length;byte[] ddxByteArray = new byte[ddxLen];int mapLen = (int)mapFs.Length;byte[] mapByteArray = new byte[mapLen];int optionsLen = (int)optionsFs.Length;byte[] optionsByteArray = new byte[optionsLen];// Populate the byte arrays with the contents of the file streamsddxFs.Read(ddxByteArray, 0, ddxLen);mapFs.Read(mapByteArray, 0, mapLen);optionsFs.Read(optionsByteArray, 0, optionsLen);// Populate the BLOB objectsddxDoc.binaryData = ddxByteArray;mapDoc.binaryData = mapByteArray;optionsDoc.binaryData = optionsByteArray;// Create the map containing the PDF source documentsmapItem[] inputMap = new mapItem[2];inputMap[0] = new mapItem();inputMap[1] = new mapItem();inputMap[0].key = "map.pdf";inputMap[0].value = mapDoc;inputMap[1].key = "optionsLink.pdf";inputMap[1].value = optionsDoc;// Create an AssemblerOptionsSpec objectAssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec();assemblerSpec.failOnError = true;// Send the request to the Assembler ServiceAssemblerResult result = asOb.invoke(ddxDoc,inputMap,assemblerSpec);// Extract the newly created PDF document from the returned mapBLOB outDoc = null;mapItem[] mapResult = result.documents;for (int i = 0; i < mapResult.Length; i++){String myKey = (String)(mapResult[i].key);if (myKey == "out.pdf"){outDoc = (BLOB)(mapResult[i].value);}}//Populate a byte array with the BLOBbyte[] outByteArray = outDoc.binaryData;//Create a new file containing the returned PDF documentstring FILE_NAME = "C:\\out.pdf";FileStream fs2 = new FileStream(FILE_NAME, FileMode.OpenOrCreate);BinaryWriter w = new BinaryWriter(fs2);w.Write(outByteArray);w.Close();fs2.Close();Console.WriteLine("The PDF files were assembled.");}catch (Exception ee){Console.WriteLine("An unexpected exception was encountered: " + ee.Message + "\n" + ee.StackTrace);}}}}
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/livecycle/es/sdkHelp/programmer/sdkHelp/quickStarts_Assembler.4.3.html