PDF protection
Encrypt a PDF
Set opening and owner passwords, then choose exactly what a compatible PDF reader should permit.
Ready to tryUse the controls above to interact with this demo.
What this demonstrates
Separate opening security from access permissions
The user password controls who can open the PDF. The master password protects the permission policy that governs printing, copying, form completion, and document modification.
PDF permissions are advisory controls enforced by compatible readers. TX Text Control combines the selected flags and applies them while creating the encrypted file.
API used
SaveSettings.DocumentAccessPermissions
Key members
Passwords and a bitwise DocumentAccessPermissions value are applied through SaveSettings when the encrypted PDF is saved.
var settings = new SaveSettings
{
UserPassword = request.UserPassword,
MasterPassword = request.MasterPassword,
DocumentAccessPermissions = permissions
};
textControl.Save(out byte[] encrypted, BinaryStreamType.AdobePDF, settings);
How it works
The controller builds a bitwise DocumentAccessPermissions value, assigns both passwords to SaveSettings, and creates an encrypted download. A separate unencrypted copy is returned only for immediate preview in the demo.
NuGet packages
TXTextControl.TextControl.Core.SDK
34.0.4
Provides the core document model and server-side document processing APIs.
dotnet add package TXTextControl.TextControl.Core.SDK --version 34.0.4
Displays supported document and PDF formats in the browser.
dotnet add package TXTextControl.Web.DocumentViewer --version 34.2.0
Source files
See the implementation
The complete demo is encapsulated in Demos/Pdf/Security/Encryption.