Quick Start (MTOM): Removing usage rights from a PDF document using the web service API

The following C# code example removes usage rights from a rights-enabled PDF document named LoanUsageRights.pdf. The document is saved as a PDF file named noUsageRightsLoan.pdf . (See Removing Usage Rights from 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 AEM forms   
    */ 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ServiceModel; 
using System.IO; 
using RemoveUsageRights.ServiceReference1; 
 
namespace RemoveUsageRights 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
               try 
               { 
                   //Create a RightsManagementServiceClient object 
                   ReaderExtensionsServiceClient reClient = new ReaderExtensionsServiceClient(); 
                   reClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://[server]:[port]/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; 
 
                   //Create a BLOB object to store the rights-enabled PDF document  
                   BLOB inDoc = new BLOB(); 
 
                   //Specify the rights-enabled 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; 
 
                   //Remove usage rights from the PDF document 
                   BLOB outDoc = reClient.removeUsageRights(inDoc); 
 
                   //Populate a byte array with a BLOB data 
                   byte[] outByteArray = outDoc.MTOM; 
 
                   //Create a new file  
                   string FILE_NAME = "C:\\Adobe\noUsageRightsLoan.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