# PDF Passwords and Permissions

> UserPassword, MasterPassword and PDF permissions compared: apply the permissions of an opened PDF to the WPF TextControl and check saved files for encryption.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Security > PDF Passwords and Permissions
- **2370 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/security/pdf-passwords/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/security/pdf-passwords/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/security/pdf-passwords/llms-full.txt

---

A PDF carries its own protection: a user password that encrypts it and a master password that guards a set of permissions for PDF readers. The two are easy to confuse, and only the first keeps a document confidential. For a WPF application that saves protected PDF documents or opens those of others, what follows explains what each setting achieves, how the permissions of an opened PDF reach the `TextControl` and how to prove that a saved file is encrypted.

The save settings themselves, with code for each permission, are shown in [Passwords and Access Permissions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/passwords/llms-full.txt).

### Passwords and Permissions Compared

Three save settings protect a PDF: [UserPassword](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/loadsavesettingsbase/userpassword-property/llms-full.txt) encrypts the document so that it can't be opened without the password, [MasterPassword](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/loadsavesettingsbase/masterpassword-property/llms-full.txt) guards the permissions, and [DocumentAccessPermissions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/documentaccesspermissions-property/llms-full.txt) lists what readers may do, which takes effect only together with a master password. [How PDF Passwords Work](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/passwords/#how-pdf-passwords-work) describes the properties and the values of the permissions.

### Why Permissions Aren't Enough

Text Control's articles on PDF security make four points:

1. **A permission is a request to the reader.** Compliant readers such as Adobe Acrobat honor it, and others can ignore it. Permissions are no cryptographic protection.
2. **Confidential content needs encryption.** Use a user password, and treat permissions as a policy added to it.
3. **The master password grants everything.** Opening the document with it gives all permissions. Text Control therefore recommends a master password that differs from the user password.
4. **Neither password proves integrity.** To show that a document wasn't changed and who created it, sign it, as [Certificate and Private Key Handling](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/security/certificates/llms-full.txt) explains.

### Respect the Permissions of a PDF

TX Text Control decrypts an encrypted PDF when it loads it, and the rest is up to your application: getting the passwords from the user and restricting operations that the document doesn't allow. The permissions are available after loading in [LoadSettings.DocumentAccessPermissions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/loadsettings/documentaccesspermissions-property/llms-full.txt). With the correct master password, they are `AllowAll`.

The following method in *MainWindow.xaml.cs* loads a PDF into `textControl1` and turns its permissions into restrictions of the editor. The file needs `using TXTextControl;`:

```csharp
private bool LoadPdf(string path, string userPassword)
{
    LoadSettings loadSettings = new LoadSettings()
    {
        UserPassword = userPassword
    };

    try
    {
        textControl1.Load(path, StreamType.AdobePDF, loadSettings);
    }
    catch (FilterException exception) when (exception.Reason == FilterException.FilterError.InvalidPassword)
    {
        // Missing or wrong user password: ask the user and call LoadPdf again
        return false;
    }

    // Apply the permissions of the PDF to the editor
    DocumentAccessPermissions permissions = loadSettings.DocumentAccessPermissions;

    if (permissions != DocumentAccessPermissions.AllowAll)
    {
        DocumentPermissions editorPermissions = textControl1.DocumentPermissions;
        editorPermissions.ReadOnly = !permissions.HasFlag(DocumentAccessPermissions.AllowGeneralEditing);
        editorPermissions.AllowFormatting = permissions.HasFlag(DocumentAccessPermissions.AllowGeneralEditing);
        editorPermissions.AllowCopy = permissions.HasFlag(DocumentAccessPermissions.AllowExtractContents);
        editorPermissions.AllowPrinting = permissions.HasFlag(DocumentAccessPermissions.AllowLowLevelPrinting)
            || permissions.HasFlag(DocumentAccessPermissions.AllowHighLevelPrinting);
        editorPermissions.AllowEditingFormFields = permissions.HasFlag(DocumentAccessPermissions.AllowAuthoringFields);

        textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect;
    }

    return true;
}
```

The code works as follows:

- [WPF.TextControl.Load](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/load-method/llms-full.txt) throws a [FilterException](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/filterexception/llms-full.txt) with the [Reason](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/filterexception/reason-property/llms-full.txt) `InvalidPassword` if the user password is missing or wrong. Then the method returns `false`, and your window asks for the password and calls it again.
- The permissions are flags that can be combined, such as `AllowGeneralEditing`, `AllowExtractContents`, `AllowHighLevelPrinting` and `AllowAuthoringFields`. `AllowAll` includes every flag, so a PDF without restrictions stays fully editable.
- The flags set the properties of the [DocumentPermissions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/documentpermissions/llms-full.txt) object that [WPF.TextControl.DocumentPermissions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/documentpermissions-property/llms-full.txt) returns, and [EditMode](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/editmode-property/llms-full.txt) set to `ReadAndSelect` activates them. Before the next document is loaded, set `EditMode` back to `EditMode.Edit`.
- Commands of your own, such as a print button, check [CanPrint](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/canprint-property/llms-full.txt) or [CanCopy](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/cancopy-property/llms-full.txt) before they run.

Some PDF documents can't be decrypted at all: AES with a 256-bit key and certificate-based encryption make `Load` throw a `FilterException` with the reason `Encrypted`. [Encrypted PDF Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/import/#encrypted-pdf-documents) lists what TX Text Control imports.

### Check That a PDF Is Encrypted

A process that forgets the user password produces a readable PDF without any error. Text Control's advice for automated workflows is to check the result: loading a PDF that has a user password fails without it. This method returns `true` when that is the case:

```csharp
private static bool IsEncrypted(string path)
{
    using (ServerTextControl tx = new ServerTextControl())
    {
        tx.Create();

        try
        {
            // Loading without a password must fail
            tx.Load(path, StreamType.AdobePDF);
            return false;
        }
        catch (FilterException exception) when (exception.Reason == FilterException.FilterError.InvalidPassword)
        {
            return true;
        }
    }
}
```

The code works as follows:

- A [ServerTextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/llms-full.txt) has no user interface, so the check doesn't touch the document in the window. [Create](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/create-method/llms-full.txt) comes before any other member.
- When [Load](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/load-method/llms-full.txt) succeeds, the file opens without a password and isn't encrypted. Load errors with other reasons, such as a damaged file, are passed on to the caller.

In the blog article [PDF Security Explained: Passwords, Permissions, Encryption and Digital Signatures in C# .NET](https://www.textcontrol.com/blog/2026/06/08/pdf-security-explained-passwords-permissions-encryption-and-digital-signatures-in-csharp-dotnet/), the check also loads the file with the password to confirm that it opens.

### Next Steps

- [Passwords and Access Permissions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/passwords/llms-full.txt): the code for saving protected PDF documents.
- [Handling Untrusted Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/security/untrusted-documents/llms-full.txt): accepted formats, load errors and links.
- [Certificate and Private Key Handling](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/security/certificates/llms-full.txt): sign what you encrypt.
- The blog article [PDF Security for C# Developers: Encryption and Permissions in .NET](https://www.textcontrol.com/blog/2025/06/16/pdf-security-for-csharp-developers-encryption-and-permissions-in-dotnet/): the permission values and their effect in PDF readers.

---

## Nearby

- **Previous:** [Handling Untrusted Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/security/untrusted-documents/llms-full.txt)
- **Next:** [Certificate and Private Key Handling](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/security/certificates/llms-full.txt)
