TL;DR: Learn how to implement credential-based PDF access in WPF applications using encrypted documents and permission flags. This guide shows how to securely load PDFs with owner or user credentials, suppress password prompts, and enforce document-level restrictions.
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 basics: Owner vs. user passwords
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.
Owner password
- Grant complete administrative control over the PDF document.
- Allows the document creator to define restrictions on actions such as printing, copying content, editing annotations, filling form fields, and more.
- Primarily used to configure permission flags that determine user capabilities.
User password
- Grants limited access based on the permissions set by the owner.
- Users can open and view the document, but actions like printing, copying, or editing may be restricted.
- Ideal for securely sharing documents without exposing sensitive features or content.
Permission flags and their effects in WPF PDF Viewer
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.
Credential-based access: WPF sample implementation
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.
Application overview
The application includes two buttons:
- Open with owner password: Loads the PDF with full access.
- Open with user password: Loads the PDF with restricted access.
Both buttons open the same encrypted PDF file with different credentials, highlighting how permissions affect the viewer’s capabilities.
Key implementation highlights
This sample demonstrates how to securely and seamlessly load encrypted PDFs using Syncfusion’s WPF PDF Viewer.
1. Programmatic password handling
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
};
2. Secure password storage
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;
}
GitHub reference
Ready to secure your viewer? You can explore the full sample on the GitHub demo.
Conclusion
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!
Related Blogs
- Smart PDF Redaction in WPF Using Azure OpenAI for Privacy & Compliance
- Build AI-Powered Smart Form Filling App Using WPF PDF Viewer
- Easily Export WPF DataGrid to PDF
- Navigate PDF Annotations in a TreeView Using WPF PDF Viewer
This article was originally published at Syncfusion.com.
Top comments (0)