Quick Start (MTOM): Applying usage rights using the web service API

The following C# code example applies usage rights to a PDF document named Loan.pdf. The rights-enabled PDF document is saved as a PDF file named LoanUsageRights.pdf. The following usage rights are applied to this PDF document: enabledComments, enabledFormFillIn, and enabledDigitalSignatures. (See Applying Usage Rights 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; 
using ApplyUsageRights.ServiceReference1; 
 
namespace ApplyUsageRights 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
               try 
               { 
                   //Create a RightsManagementServiceClient object 
                   ReaderExtensionsServiceClient reClient = new ReaderExtensionsServiceClient(); 
                   reClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/ReaderExtensionsService?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b = (BasicHttpBinding)reClient.Endpoint.Binding; 
                   b.MessageEncoding = WSMessageEncoding.Mtom; 
                   reClient.ClientCredentials.UserName.UserName = "administrator"; 
                   reClient.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 to store a rights-enabled PDF document 
                   BLOB inDoc = new BLOB(); 
 
                   //Specify a rights-enabled PDF document 
                   string path = "C:\\Adobe\LoanUsageRights.pdf"; 
                   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;  
 
                   //Create a UsageRight object and specify usage rights 
                   UsageRights useRight = new UsageRights(); 
                   useRight.enabledComments = true; 
                   useRight.enabledFormFillIn = true; 
                   useRight.enabledDigitalSignatures = true; 
 
                   //Create a ReaderExtensionsOptions object 
                   ReaderExtensionsOptionSpec reOptions = new ReaderExtensionsOptionSpec(); 
                   reOptions.usageRights = useRight; 
                   reOptions.message = "This is a Rights-Enabled PDF Document"; 
 
                   //Apply usage rights to a PDF document 
                   BLOB outDoc = reClient.applyUsageRights( 
                       inDoc, 
                       "RE2", 
                       null, 
                       reOptions);  
 
                   //Populate a byte array with BLOB data 
                   byte[] outByteArray = outDoc.MTOM; 
 
                   //Create a new file named UsageRightsLoan.pdf 
                   string fileName = "C:\\Adobe\LoanUsageRights.pdf"; 
                   FileStream fs2 = new FileStream(fileName, 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