Check Document Password Protection

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Merger MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-merger -- dnx GroupDocs.Merger.Mcp --yes
Folders, licensing and more →

GroupDocs.Merger for Python via .NET lets you check whether a document has an open password set. The is_password_set() method on the Merger instance returns True if the document requires a password to open, or False otherwise.

Steps to check document password protection

  1. Open the document with Merger. If the document is already password-protected, supply the password via LoadOptions; otherwise omit it.
  2. Call merger.is_password_set() and inspect the return value.
from groupdocs.merger import Merger
from groupdocs.merger.domain.options import LoadOptions

def check_document_password_protection():
    # Provide the current password so the protected document can be opened
    load_options = LoadOptions(password="p@ss")
    # Load the password-protected document
    with Merger("./protected.pdf", load_options) as merger:
        # Returns True if the document has an open password set
        protected = merger.is_password_set()
        print("Is password set:", protected)

if __name__ == "__main__":
    check_document_password_protection()

protected.pdf is a sample file used in this example. Click here to download it.

Is password set: True

Download full output

Note
is_password_set() is a method on the Merger instance, not a property of the document information object returned by get_document_info().

Explanation

  • Supply Load Password: LoadOptions(password="p@ss") allows Merger to open the encrypted document. Without this, opening a protected document raises IncorrectPasswordException.
  • Load Document: The Merger context manager opens the document using the provided credentials.
  • Check Protection: merger.is_password_set() interrogates the loaded document and returns True if an open password is present, False if the document is unprotected.

Refer to the GroupDocs.Merger API Reference for more details on is_password_set() and LoadOptions.

See also