Examples

Encrypt PDF (.NET Core/Framework)

In the following two examples, you encrypt a PDF using DynamicPDF Generator followed by DynamicPDF Merger. Listed below are steps illustrating both encryption methods.

Watch the Video

How to Encrypt PDF

Download the NuGet package and GitHub package to get started. The following steps illustrate encrypting a PDF using DynamicPDF Generator followed by encrypting a PDF using DynamicPDF Merger.

You use the Aes128Security, Aes256Security, RC4128Security, and RC440Security classes present in ceTe.DynamicPDF.Cryptography namespace 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.
  3. Create a Aes256Security object by setting the owner and user password.
  4. Set the required security properties and the security to the Document.
  5. Invoke the Draw method on the Document 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 the security to the Document.
  4. Invoke the Draw method on the Document 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");

Getting Started

NuGet Package

DynamicPDF Generator is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET package. The Core Suite package includes Generator, Merger and ReportWriter.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

GitHub Example Project

Clone or view the example project at GitHub. This example is is the Examples/EncryptPDF.cs file.

Clone or View Example Project on GitHub

DynamicPDF Generator and Merger Information

More information can be found here:

Java and COM/ActiveX Platforms

The DynamicPDF Generator and DynamicPDF Merger are also available for 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 18 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

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