Examples

Encrypt PDF

In the following two examples, you encrypt a PDF using DynamicPDF Core Suite. Listed below are steps illustrating both encryption methods.

Watch the Video

How to Encrypt PDF

The following classes are present in ceTe.DynamicPDF.Cryptography namespace and are used to encrypt PDF documents.

Some of the more common security settings you can use include:

  • if the accessibility programs should be able to read a document's text and images for a user,
  • if a document can be assembled and manipulated by a user,
  • if form filling is allowed by a user,
  • if a document can be printed at a high resolution by a user,
  • and if a document's components can be encrypted.

Steps for Encrypting a New PDF Document

  1. Create a Document object.
  2. Create a Page object and add it to Document instance.
  3. Create a Aes256Security object by setting the owner and user password.
  4. Set the required security properties and apply the security to the Document Instance.
  5. Invoke the Draw method on the Document instance to output the PDF.

Sample Code - C#

Document document = new Document();
           
Page page = new Page();
document.Pages.Add(page);
           
Aes256Security security = new Aes256Security("OwnerPassword", "UserPassword");
security.AllowAccessibility = true;
security.AllowFormFilling = false;            
document.Security = security;

document.Draw("Output.pdf");

Steps for Encrypting an Existing PDF Document

  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 required security properties and apply the security to the Document instance.
  4. Invoke the Draw method on the Document instance to output the PDF.

Sample Code - C#

MergeDocument document = new MergeDocument("DocumentA.pdf");

Aes256Security security = new Aes256Security("OwnerPassword", "UserPassword");
security.AllowCopy = false;
security.AllowPrint = false;
document.Security = security;

document.Draw("Output.pdf");

GitHub Project

Clone or view the example project at GitHub. This examples contained on this page are in the Examples/EncryptPDF.cs file.

Clone or View Example Project on GitHub

Getting Started

NuGet Package

DynamicPDF Generator is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET package. The easiest way to install the package is through the Visual Studio Package Manager. You can also download the package directly from NuGet.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

DynamicPDF Core Suite Information

More information on the Dynamic Core Suite can be found on its website.

Available on Other Platforms

The DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details. Note that these products, although combined into one product for DynamicPDF Core Suite, remain as separate products for the Java and COM/ActiveX platforms.

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!