Quick Start (MTOM): Transforming a PDF document using the web service API

The following C# code example transforms an interactive PDF document named Loan.pdf into a non-interactive PDF document namedNonInteractiveLoan.pdf. (See Flattening 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   
    */ 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ServiceModel; 
using System.IO; 
 
//A reference to the Output service  
using TransformPDF.ServiceReference1; 
 
 
namespace TransformPDF 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
               try 
               { 
                   //Create an OutputServiceClient object 
                   OutputServiceClient outputClient = new OutputServiceClient(); 
                   outputClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/OutputService?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b = (BasicHttpBinding)outputClient.Endpoint.Binding; 
                   b.MessageEncoding = WSMessageEncoding.Mtom; 
                   outputClient.ClientCredentials.UserName.UserName = "administrator"; 
                   outputClient.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 a BLOB object 
                   BLOB inData = new BLOB(); 
 
                   //Reference an interactive PDF document 
                   string inputFileName = "C:\\Adobe\Loan.pdf"; 
                   FileStream fs = new FileStream(inputFileName, FileMode.Open); 
 
                   //Get the length of the file stream and create a byte array  
                   int len = (int)fs.Length; 
                   byte[] byteArray = new byte[len]; 
 
                   //Populate the byte array with the contents of the file stream 
                   fs.Read(byteArray, 0, len); 
 
                   //Populate the BLOB object 
                   inData.MTOM = byteArray; 
 
                   //Set rendering run-time options  
                   RenderOptionsSpec renderOptions = new RenderOptionsSpec(); 
                   renderOptions.cacheEnabled = true; 
 
                   //Create a non-interactive PDF document 
                   BLOB results = outputClient.transformPDF( 
                       inData, 
                       TransformationFormat.PDF, 
                       PDFARevisionNumber.Revision_1, 
                       null, 
                       PDFAConformance.A); 
 
                   //Populate a byte array with a BLOB data 
                   byte[] outByteArray = results.MTOM; 
 
                   //Create a new file that represents the non-interactive PDF document 
                   string FILE_NAME = "C:\\Adobe\NonInteractiveLoan.pdf"; 
                   FileStream fs2 = new FileStream(FILE_NAME, FileMode.OpenOrCreate); 
 
                   //Create a BinaryWriter object 
                   BinaryWriter w = new BinaryWriter(fs2); 
                   w.Write(outByteArray); 
                   w.Close(); 
                   fs2.Close(); 
               } 
 
               catch (Exception ee) 
               { 
                   Console.WriteLine(ee.Message); 
               } 
           } 
       } 
} 

// Ethnio survey code removed