Quick Start (MTOM): Converting a Microsoft Word document to a PDF document using the web service API

The following C# .NET example converts a Word file named Loan.doc to a PDF document named Loan.pdf. (See Converting Word Documents to 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 Generate PDF service  
using ConvertWordDoc.ServiceReference1; 
 
namespace ConvertWordDoc 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
               try 
               { 
                   //Create a GeneratePDFService object 
                   GeneratePDFServiceClient pdfGenClient = new GeneratePDFServiceClient(); 
                   pdfGenClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://pdf-generator:8080/soap/services/GeneratePDFService?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b = (BasicHttpBinding)pdfGenClient.Endpoint.Binding; 
                   b.MessageEncoding = WSMessageEncoding.Mtom; 
                   pdfGenClient.ClientCredentials.UserName.UserName = "administrator"; 
                   pdfGenClient.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 that represents the input Microsoft Word file 
                   BLOB inDoc = new BLOB(); 
                   String path = "C:\\Adobe\\Loan.doc"; 
                   FileStream fs = new FileStream(path, FileMode.Open); 
 
                   //Get the length of the file stream  
                   int len = (int)fs.Length; 
                   byte[] ByteArray = new byte[len]; 
 
                   //Populate the byte array with the contents of the FileStream object 
                   fs.Read(ByteArray, 0, len); 
                   inDoc.MTOM = ByteArray; 
 
                   // Specify the PDF and security settings  
                   String adobePDFSettings = "Standard"; 
                   String securitySettings = "No Security"; 
     
                   BLOB createdDocument = new BLOB(); 
                   BLOB logDocument = new BLOB();  
 
                   //Convert the Word file to a PDF document 
                   pdfGenClient.CreatePDF2( 
                       inDoc, 
                       "DOC", 
                       null, 
                       adobePDFSettings, 
                       securitySettings, 
                       null, 
                       null, 
                       out createdDocument, 
                       out logDocument 
                       ); 
 
                //Save the converted PDF document 
                 byte[] outByteArray = createdDocument.MTOM; 
 
                 //Create a new file to store result data 
                 string FILE_NAME = "C:\\Adobe\\Loan.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