Quick Start (MTOM): Determining whether a document is PDF/A compliant using the web service API

The following C# code example determines whether the input PDF document is PDF/A compliant. The input PDF document that is passed to the Assembler service is named Loan.pdf. The name of the DDX document is shell_PDFA.xml. The XML document that is returned from the Assembler service and specifies whether the input PDF document is PDF/A compliant is saved as an XML file named result.xml. (See Determining Whether Documents Are PDF/A- Compliant.)

???/** 
    * 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/"> 
    *        <DocumentInformation source="Loan.pdf" result="Loan_result.xml"> 
    *        <PDFAValidation compliance="PDF/A-1b" resultLevel="Detailed"  
    *        ignoreUnusedResources="true" allowCertificationSignatures="true" /> 
    *    </DocumentInformation> 
    *</DDX> 
    */ 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ServiceModel; 
using System.IO; 
using PDFACompliant.ServiceReference1; 
 
namespace PDFACompliant 
{ 
       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 input PDF document 
                   BLOB ddxDoc = new BLOB(); 
                   BLOB pdfDoc = new BLOB(); 
 
                   // Get the input DDX document and input PDF document 
                   string ddxFileName = "C:\\shell_PDFA.xml"; 
                   FileStream ddxFs = new FileStream(ddxFileName, FileMode.Open); 
                   string pdfFile = "C:\\Adobe\Loan.pdf"; 
                   FileStream pdfFs = new FileStream(pdfFile, FileMode.Open); 
 
                   // Get the lengths of the file streams and create byte arrays 
                   int ddxLen = (int)ddxFs.Length; 
                   byte[] ddxByteArray = new byte[ddxLen]; 
                   int pdfLen = (int)pdfFs.Length; 
                   byte[] pdfByteArray = new byte[pdfLen]; 
     
                   // Populate the byte arrays with the contents of the file streams 
                   ddxFs.Read(ddxByteArray, 0, ddxLen); 
                   pdfFs.Read(pdfByteArray, 0, pdfLen); 
     
                   // Populate the BLOB objects 
                   ddxDoc.MTOM = ddxByteArray; 
                   pdfDoc.MTOM = pdfByteArray; 
 
                   // Create the map containing the PDF source document 
                   MyMapOf_xsd_string_To_xsd_anyType inputMap = new MyMapOf_xsd_string_To_xsd_anyType(); 
     
                   MyMapOf_xsd_string_To_xsd_anyType_Item inLoanDoc = new MyMapOf_xsd_string_To_xsd_anyType_Item(); 
                   inLoanDoc.key = "Loan.pdf"; 
                   inLoanDoc.value = pdfDoc; 
                   inputMap.Add(inLoanDoc); 
     
                   // Create an AssemblerOptionsSpec object 
                   AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec(); 
                   assemblerSpec.failOnError = false; 
 
                   // Send the request to the Assembler Service 
                   AssemblerResult result = assembleClient.invoke(ddxDoc, inputMap, assemblerSpec); 
 
                   //Extract the XML document that specifies whether 
                   //the input PDF is PDF/A compliant 
                   BLOB outDoc = null; 
                   PDFACompliant.ServiceReference1.Map mapResult = result.documents; 
                   for (int i = 0; i < mapResult.Count; i++) 
                   { 
                       String myKey = (String)(mapResult[i].key); 
 
                       if (myKey == "Loan_result.xml") 
                       { 
                           outDoc = (BLOB)(mapResult[i].value); 
                       } 
                   } 
 
                   //Populate a byte array with the BLOB 
                   byte[] outByteArray = outDoc.MTOM; 
 
                   //Create a new file containing the returned PDF document 
                   string FILE_NAME = "C:\\result.xml"; 
                   FileStream fs2 = new FileStream(FILE_NAME, FileMode.OpenOrCreate); 
                   BinaryWriter w = new BinaryWriter(fs2); 
                   w.Write(outByteArray); 
                   w.Close();     
                   fs2.Close(); 
 
                   Console.WriteLine("The results are written to result.xml."); 
               } 
 
               catch (Exception ee) 
               { 
                   Console.WriteLine("An unexpected exception was encountered: " + ee.Message + "\n" + ee.StackTrace); 
               } 
           } 
       } 
} 
 
 

// Ethnio survey code removed