Quick Start (MTOM): Converting a PDF document to a set of JPEG files using the web service API

The following C# code example converts a PDF document called Loan.pdf to a set of JPEG files and stores them in the C:\Adobe directory. Each file is named tempFile[index].jpg, where the first image file is named tempFile0.jpg. (See Converting PDF Documents to Image Formats.)

???/** 
    * 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 ConvertPDFtoImage.ServiceReference1; 
 
namespace ConvertPDFtoImage 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
               try 
               { 
                   //Create a ConvertPdfService object 
                   ConvertPdfServiceClient convertPdfClient = new ConvertPdfServiceClient(); 
                   convertPdfClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/ConvertPDFService?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b = (BasicHttpBinding)convertPdfClient.Endpoint.Binding; 
                   b.MessageEncoding = WSMessageEncoding.Mtom; 
                   convertPdfClient.ClientCredentials.UserName.UserName = "administrator"; 
                   convertPdfClient.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 PDF file 
                   BLOB inDoc = new BLOB(); 
 
                   // Get the input 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 
                   inDoc.MTOM = byteArray; 
 
                   //Set up the runtime options for the new JPEG files to create 
                   ToImageOptionsSpec spec = new ToImageOptionsSpec(); 
                   spec.imageConvertFormat = ImageConvertFormat.JPEG; 
                   spec.grayScaleCompression = GrayScaleCompression.Low; 
                   spec.colorCompression = ColorCompression.Low; 
                   spec.format = JPEGFormat.BaselineOptimized; 
                   spec.rgbPolicy = RGBPolicy.Off; 
                   spec.cmykPolicy = CMYKPolicy.Off; 
                   spec.colorSpace = ColorSpace.RGB; 
                   spec.resolution = "72"; 
                   spec.monochrome = MonochromeCompression.None; 
                   spec.filter = PNGFilter.Sub; 
                   spec.interlace = Interlace.Adam7; 
                   spec.tileSize = 180; 
                   spec.grayScalePolicy = GrayScalePolicy.Off; 
 
                   //Send the conversion request to the ConvertPDF Service 
                   MyArrayOfBLOB allImages = convertPdfClient.toImage2(inDoc, spec); 
 
                   //Get the length of the object array 
                   int arrLen = allImages.Count; 
 
                   //Get all images from the Object array 
                   for (int i = 0; i < arrLen; i++) 
                   { 
                       BLOB imageData = (BLOB)allImages[i]; 
 
                       //Populate a byte array with a BLOB data 
                       byte[] outByteArray = imageData.MTOM; 
 
                       //Create a new file that represents the image 
                       string FILE_NAME = "C:\\Adobe\tempFile" + i + ".jpg"; 
                       FileStream fs2 = new FileStream(FILE_NAME, FileMode.OpenOrCreate); 
 
                       //Create a BinaryWriter object 
                       BinaryWriter w = new BinaryWriter(fs2); 
                       w.Write(outByteArray); 
                       w.Close(); 
                       fs2.Close(); 
                   } 
                   Console.WriteLine("The PDF file was converted to a set of JPEG document(s)."); 
               } 
               catch (Exception ee) 
               { 
                   Console.WriteLine(ee.Message); 
               } 
           } 
       } 
} 

// Ethnio survey code removed