Skip to Content

Controlling PDF Access: Applying Restrictions with Adobe PDF Library in .NET Core

Estimated Reading Time: 2 Minutes

Controlling access to PDF content is essential for organizations looking to protect sensitive information. This guide explains how to apply restrictions to a PDF using Adobe PDF Library (APDFL) in a .NET Core environment, specifically to prevent users from copying or selecting text, even when viewing the document in web browsers like Chrome.

Objective

The goal is to apply permissions to a PDF that block both copying and text selection. While copying restrictions are straightforward, preventing text selection requires precise configuration using the correct combination of security settings within the APDFL library.


 Understanding Permission Flags

In APDFL, the PermissionFlags enumeration controls permissions on the document. Although an enumeration type, perms acts as a 32-bit unsigned integer with the majority of PermissionFlags representing individual bit positions listed in ISO 32000-2, Table 22 — Standard Security Handler User Access Permissions.


Core Implementation

To apply permissions, we utilize the Secure method:​

 doc.Secure(perms, sOwnerPwd, sUserPwd,EncryptionType.AES256_AcroX,false);

Here, the perms parameter specifies the features allowed or restricted in the output PDF.​


Working with Permission Flags

1.      Initializing Permissions

Begin by setting a base value for permissions:

PermissionFlags perms = PermissionFlags.Open | PermissionFlags.Owner;

 

This initialization grants basic access rights, which can be adjusted as needed:

perms = PermissionFlags.User; // Assigns user-level permissions

perms = PermissionFlags.All;  // Grants all permissions

 

2.      Modifying Permissions Using Bitwise Operators

Adjust specific permissions by employing bitwise operators:

o   Enabling permissions: Use the OR operator (|=) to allow actions:​

perms |= PermissionFlags.Print; // Allows printing

o   Disabling permissions: Use the AND NOT operator (&= ~) to prohibit actions:​

perms &= ~PermissionFlags.Print; // Disallows printing

This approach provides a flexible, programmatic method to customize document access according to specific requirements.

 

A focused callout highlighting the Secure method and permission manipulation:

// Initialize permissions

PermissionFlags perms = PermissionFlags.Open | PermissionFlags.Owner;

 

// Disable text copying and selection

perms &= ~PermissionFlags.Copy;

perms &= ~PermissionFlags.Accessible;

 

// Implement security settings for the document 

doc.Secure(perms, "ownerPassword", "userPassword", EncryptionType.AES256_AcroX, false);


Final Outcome

By following this process, both copying and text selection were successfully restricted in Adobe Acrobat, meeting the customer's security requirements. While restrictions may not be fully respected in all viewers (e.g., web browsers), the implementation provides strong protection in supported environments.


How to Get Additional Help If Needed

For further assistance or if you encounter any issues while implementing PDF restrictions using the APDFL libraries, you can reach out for support. You can send an email to our technical support team at tech_support@datalogics.com.

Additionally, you can explore our extensive documentation available at https://docs.datalogics.com, which provides detailed guidance on various functionalities and troubleshooting steps related to our software.

For any further inquiries or updates, feel free to visit our main website at https://www.datalogics.com.

 

Controlling PDF Access: Applying Restrictions with Adobe PDF Library in .NET Core
  • COMMENT