Quick Start (MTOM): Assembling a non-interactive PDF document using the web service API

The following C# code example assembles a non-interactive PDF document. The interactive PDF document that is passed to the Assembler service is named Loan.pdf. Notice that the name of the DDX document is shell_XFA.xml. The non-interactive PDF document is saved as a PDF file named AssembleNonInteractivePDF.pdf. (See Assembling Non-Interactive PDF Documents.)

???/** 
    * Ensure that you create a .NET project that uses  
    * MS Visual Studio 2008 and version 3.5 of the .NET 
    * framework. This is required to invoke a  
    * LiveCycle service using MTOM. 
    *      
    * For information, see "Invoking LiveCycle using MTOM" in Programming with LiveCycle. 
    *  
    * The following XML represents the DDX document used in this quick start: 
    * <?xml version="1.0" encoding="UTF-8"?> 
    * <DDX xmlns="http://ns.adobe.com/DDX/1.0/"> 
    * <PDF result="out.pdf"> 
    *   <PDF source="inDoc"/> 
    *   <NoXFA/> 
    * </PDF> 
    * </DDX> 
    */ 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ServiceModel; 
using System.IO; 
using NonInteractiveDocument.ServiceReference1; 
 
namespace NonInteractiveDocument 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
               try 
               { 
                   //Create an AssemblerServiceClient object 
                   AssemblerServiceClient assembleClient = new AssemblerServiceClient(); 
                   assembleClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/AssemblerService?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b = (BasicHttpBinding)assembleClient.Endpoint.Binding; 
                   b.MessageEncoding = WSMessageEncoding.Mtom; 
                   assembleClient.ClientCredentials.UserName.UserName = "administrator"; 
                   assembleClient.ClientCredentials.UserName.Password = "password"; 
                   b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
                   b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
                   b.MaxReceivedMessageSize = 2000000; 
                   b.MaxBufferSize = 2000000; 
                   b.ReaderQuotas.MaxArrayLength = 2000000; 
 
 
                   // Create BLOB objects that represents the input  
                   // DDX file and the interactive PDF document 
                   BLOB ddxDoc = new BLOB(); 
                   BLOB LoanDoc = new BLOB(); 
 
                   // Get the input DDX document and input PDF file 
                   string ddxFileName = "C:\\shell_XFA.xml"; 
                   FileStream ddxFs = new FileStream(ddxFileName, FileMode.Open); 
                   string pdfFileName = "C:\\Adobe\Loan.pdf"; 
                   FileStream loanFs = new FileStream(pdfFileName, FileMode.Open); 
 
                   // Get the file stream lengths and create byte arrays 
                   int ddxLen = (int)ddxFs.Length; 
                   byte[] ddxByteArray = new byte[ddxLen]; 
                   int loanLen = (int)loanFs.Length; 
                   byte[] loanByteArray = new byte[loanLen]; 
 
                   // Populate the byte arrays with the contents of the file streams 
                   ddxFs.Read(ddxByteArray, 0, ddxLen); 
                   loanFs.Read(loanByteArray, 0, loanLen); 
 
                   // Populate the BLOB objects 
                   ddxDoc.MTOM = ddxByteArray; 
                   LoanDoc.MTOM = loanByteArray; 
 
                   // Create an AssemblerOptionsSpec object 
                   AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec(); 
                   assemblerSpec.failOnError = false; 
 
                   // Send the request to the Assembler Service 
                   BLOB outDoc = assembleClient.invokeOneDocument(ddxDoc, LoanDoc, assemblerSpec); 
 
                   //Populate a byte array with BLOB data 
                   byte[] outByteArray = outDoc.MTOM; 
 
                   //Create a new file containing the returned PDF document 
                   string FILE_NAME = "C:\\AssembleNonInteractivePDF.pdf"; 
                   FileStream fs2 = new FileStream(FILE_NAME, FileMode.OpenOrCreate); 
                   BinaryWriter w = new BinaryWriter(fs2); 
                   w.Write(outByteArray); 
                   w.Close(); 
                   fs2.Close(); 
 
                   Console.WriteLine("The non-interactive PDF file was assembled."); 
               } 
 
               catch (Exception ee) 
               { 
                   Console.WriteLine("An unexpected exception was encountered: " + ee.Message + "\n" + ee.StackTrace); 
               } 
           } 
       } 
} 

// Ethnio survey code removed