Examples

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


  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.


Clone or View Example Project on GitHub

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.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

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.


Why Choose DynamicPDF?

  • Transparent Pricing
  • Lots of Features
  • Easy to Use
  • Great Support
  • Efficient Performance
  • Product Maturity (Over 22 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

We’re Not The Only Ones That Think We’re Great!