TL;DR: Discover how to securely load encrypted PDFs in WPF applications using Syncfusion’s WPF PDF Viewer. This guide demonstrates implementing credential-based access with owner or user passwords, suppressing password prompts, and enforcing permission flags for robust document security.
In enterprise-grade WPF applications, secure document access isn’t optional, it’s essential. Syncfusion’s WPF PDF Viewer supports encrypted PDFs and allows developers to enforce access control using owner and user passwords.
This blog walks you through implementing credential-based access in a WPF PDF Viewer. You’ll learn how to load encrypted PDFs using owner or user passwords, enforce permission flags, and suppress default password dialogs for a seamless experience.
PDF encryption allows precise control over who can view and interact with a document. Syncfusion’s WPF PDF Viewer respects these controls and enforces them at runtime.
When a PDF is encrypted, the owner can apply permission flags (PdfPermissionTags) to restrict specific features. Syncfusion’s WPF PDF Viewer enforces these flags during runtime.
| Permission tag | Restricted features |
| Default | Copying, annotations, printing, form-filling, and redaction |
| AccessibilityCopyContent | Same as above |
| CopyContent | Restricts annotations, print, form filling, and redaction |
| AssembleDocument | Restricts copying, annotations, printing, and form-filling |
| EditAnnotations | Restricts copying, printing, and page organization |
| Print / FullQualityPrint | Restricts copying, annotations, form filling, and redaction |
| FillFields | Restricts copying, annotations, and printing |
| EditContent | Restricts copying, annotations, and printing |
Note: While the WPF PDF Viewer does not support creating encrypted PDFs, you can protect an existing document using the Syncfusion.Pdf.Base library. This lets you set the owner and user passwords, apply permission flags, and configure security settings programmatically. For implementation details, refer to the official documentation.
To demonstrate how credential-based access works, here’s a simple WPF application that loads an encrypted PDF using either the owner or user password. This sample showcases how permissions affect viewer capabilities and how to streamline the user experience by hiding the password dialog.
The application includes two buttons:
Both buttons open the same encrypted PDF file with different credentials, highlighting how permissions affect the viewer’s capabilities.
This sample demonstrates how to securely and seamlessly load encrypted PDFs using Syncfusion’s WPF PDF Viewer.
Instead of prompting the user with a password dialog, the application handles authentication through the GetDocumentPassword event,where the password is supplied directly in code. By setting e.Handled property to true, the default dialog is suppressed, allowing a silent and customized authentication flow.
pdfViewerControl.GetDocumentPassword += (sender, e) =>
{
e.Password = ConvertToSecureString("owner_or_user_password");
e.Handled = true; // Suppress default password dialog
}; Passwords are stored using SecureString, which adds an extra layer of protection by keeping the password encrypted in memory.
private SecureString ConvertToSecureString(string password)
{
var secure = new SecureString();
foreach (char c in password)
{
secure.AppendChar(c);
}
secure.MakeReadOnly();
return secure;
} Ready to secure your viewer? You can explore the full sample on the GitHub demo.
Credential-based PDF access in WPF applications empowers developers to build secure, user-friendly document workflows. Syncfusion’s WPF PDF Viewer provides a secure and flexible way to handle encrypted PDFs. By leveraging encrypted PDFs and permission flags, you can control access at a granular level, without compromising usability.
Whether you’re building internal tools or customer-facing apps, this approach ensures sensitive PDFs are handled securely and professionally.
If you’re a Syncfusion user, you can download the setup from the license and downloads page. Otherwise, you can download a free 30-day trial.
You can also contact us through our support forum, support portal, or feedback portal for queries. We are always happy to assist you!