Skip to main content

Password Protect PDF

Version: 12.0

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​

YouTube thumbnail: Watch video: Password Protect a PDFWatch video: Password Protect a PDF

How to Password Protect PDF​

The following steps and C# example code illustrate password protecting a new PDF document.

Steps to Password Protect PDF​

  1. Create a Document object.
  2. Create a Page object and add it to the Document instance.
  3. Create a Aes256Security object by setting the owner and user password.
  4. Set the Document object's security.
  5. Add the Document object's Draw 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​

  1. Create a MergeDocument object with the path to the PDF file.
  2. Create a Aes256Security object by setting the owner and user password.
  3. Set the Document object's security.
  4. 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.

View source on GitHub: Core Suite .NET Core Examples

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.

Get ceTe.DynamicPDF.CoreSuite.NET from NuGet

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!

More Information on Password Protecting​

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.