PasswordRequiredException with document security

Hello,

If a PDF document has ‘Enable Document Change’ set to false, then GroupDocs throws a PasswordRequiredException - is this intentional behaviour? As the document can still be opened in a PDF viewer without issue?

@rthomas95

The behavior you’re experiencing with the PasswordRequiredException when trying to access a PDF document that has ‘Enable Document Change’ set to false is indeed intentional. This setting restricts modifications to the document, and GroupDocs enforces this security by requiring a password to perform certain operations, even if the document can be opened in a standard PDF viewer without issue.

In GroupDocs, the PasswordRequiredException is specifically designed to handle scenarios where a password is needed to access or modify protected documents. If you encounter this exception, it indicates that the operation you are attempting requires a password due to the document’s security settings.

To handle this exception effectively, you can implement error handling in your code to catch the PasswordRequiredException and prompt the user for the password if necessary. Here’s a simple example of how you might handle this in your application:

try
{
    // Attempt to open the protected document
    var document = new Document("path/to/protected/document.pdf");
}
catch (PasswordRequiredException ex)
{
    // Handle the exception, e.g., prompt for a password
    Console.WriteLine("This document requires a password to access. Please enter the password:");
    string password = Console.ReadLine();
    
    // Try to open the document again with the provided password
    var document = new Document("path/to/protected/document.pdf", password);
}

This approach allows you to manage the security of the document while providing a way for users to access it if they have the correct password.

If you have further questions or need additional assistance, feel free to ask!

Could you please share following details and we’ll further look into this issue:

  • GroupDocs.Conversion for .NET API version that you are using
  • Sample conversion code
  • Sample/problematic PDF