Take a survey

API Quick Starts (Code Examples) > Rights Management Service API Quick Starts > Applying a policy to a PDF document using the web service API

Applying a policy to a PDF document using the web service API
The following C# code example applies a policy named Allow Copy to a PDF document named Loan.pdf. The policy set to which the policy is added is named Global Policy Set.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO ; 
 
namespace ApplyPolicy
{
	class Class1
	{
		[STAThread]
		static void Main(string[] args)
		{
			try
			{
				//Create a RightsManagementServiceService object
				RightsManagementServiceService rmClient = new RightsManagementServiceService(); 
				rmClient.Credentials = new System.Net.NetworkCredential("administrator", "password");
 
				//Create a BLOB that represents the PDF document
				//to which a policy is applied
				BLOB inDoc = new BLOB();
 
				//Reference the PDF document to which a policy is applied
				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.binaryData = byteArray;
 
				//Apply a policy to a PDF document named Loan.pdf
				BLOB outDoc = rmClient.applyPolicy(
					inDoc,
					"Loan.pdf",
					"Global Policy Set",
					"Allow Copy",
					null,
					null);
		
				//Populate a byte array with the contents of the BLOB
				byte[] outByteArray = outDoc.binaryData;
 
				//Create a new file containing the policy-protected PDF document
				string FILE_NAME = "C:\\Adobe\\PolicyProtectedLoanDoc.pdf";
				FileStream fs2 = new FileStream(FILE_NAME, FileMode.OpenOrCreate);
				BinaryWriter w = new BinaryWriter(fs2);
				w.Write(outByteArray);
				w.Close();
				fs2.Close();
				}
			catch (Exception ee)
			{
				Console.WriteLine(ee.Message);  
			}
		}
	}
}
 
 

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/livecycle/es/sdkHelp/programmer/sdkHelp/quickStarts_RightsManagement.15.9.html