Password Protecting PDFs
Use DynamicPDF Core Suite for .NET to add password protection to a new or existing PDF document. The following C# examples show you how.
Watch the Video
How to Password Protect PDF
The following steps and C# example code illustrate password protecting a new PDF document.
Steps to Password Protect PDF
- Create a
Document
object. - Create a
Page
object and add it to theDocument
instance. - Create a
Aes256Security
object by setting the owner and user password. - Set the
Document
object's security. - Add the
Document
object'sDraw
method to draw and save the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
Aes256Security security = new Aes256Security("owner", "user");
document.Security = security;
document.Draw("output.pdf");
How to Add Password to Existing PDF
The following steps and C# example code illustrate password protecting an existing PDF document.
Steps to Add Password to Existing PDF
- Create a
MergeDocument
object with the path to the PDF file. - Create a
Aes256Security
object by setting the owner and user password. - Set the
Document
object's security. - Add the
Draw
method to save the merged PDF.
Sample code - C#
MergeDocument document = new MergeDocument("pdf-a.pdf");
Aes256Security security = new Aes256Security("owner", "user");
document.Security = security;
document.Draw(@"Output.pdf");
GitHub Project
Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This example code is contained in the following files.
- C# - PasswordProtectPDF.cs
- VB.NET - PasswordProtectPDF.vb
Getting Started
Get started easily by installing DynamicPDF Core Suite for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing the product.
NuGet Package
The easiest way to install DynamicPDF Core Suite is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.
DynamicPDF Core Suite for .NET Information
DynamicPDF Core Suite for .NET combines creating, merging, and visual report creation into one powerful product for creating PDF documents. It is ideal for anyone who needs to generate PDF documents or reports or work with existing PDFs in their applications. With a free Evaluation Edition to try and with flexible and royalty-free licensing options, why not start using DynamicPDF Core Suite for .NET today!
- DynamicPDF Core Suite for .NET Product Page
- [DynamicPDF Core Suite for .NET Documentation](/docs/dotnet/dynamic-pdf-core-suite-welcome ")
More Information on Password Protecting
- Refer to the Security documentation topic, or
- Chapter 14, Securing PDF Documents, in the book DynamicPDF Core Suite for .NET by Example available on GitHub.
Available on Other Platforms
DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.
- DynamicPDF Generator
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX
- DynamicPDF Merger
- Java - DynamicPDF Merger for Java
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX