Take a survey

API Quick Starts (Code Examples) > Assembler Service API Quick Starts > Quick Start: Assembling a PDF document using the web service API

Quick Start: Assembling a PDF document using the web service API
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 object
				AssemblerServiceService asOb = new AssemblerServiceService(); 
                
				// Provide authentication credentials to the service
				asOb.Credentials = new System.Net.NetworkCredential(
					"administrator", 
					"password"
					);
 
				// Create BLOBs that represents the input DDX file and PDF sources
				BLOB ddxDoc = new BLOB();
				BLOB mapDoc = new BLOB();
				BLOB optionsDoc = new BLOB();
 
				// Get the input DDX document and input PDF sources
				string 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 arrays
				int 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 streams
				ddxFs.Read(ddxByteArray, 0, ddxLen);
				mapFs.Read(mapByteArray, 0, mapLen);
				optionsFs.Read(optionsByteArray, 0, optionsLen);
 
				// Populate the BLOB objects
				ddxDoc.binaryData = ddxByteArray;
				mapDoc.binaryData = mapByteArray;
				optionsDoc.binaryData = optionsByteArray;
 
				// Create the map containing the PDF source documents
				mapItem[] 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 object
				AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec();
				assemblerSpec.failOnError = true;
 
				// Send the request to the Assembler Service
				AssemblerResult result = asOb.invoke(ddxDoc,inputMap,assemblerSpec);
 
				// Extract the newly created PDF document from the returned map
				BLOB 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 BLOB
				byte[] outByteArray = outDoc.binaryData;
 
				//Create a new file containing the returned PDF document
				string 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