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
- Create a
Document
object. - Create a
Page
object and add it to Document instance. - Create a
Aes256Security
object by setting the owner and user password. - Set the required security properties and apply the security to the Document Instance.
- 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
- Create a
MergeDocument
object with the path to the PDF file. - Create a
Aes256Security
object by setting the owner and user password. - Set the required security properties and apply the security to the Document instance.
- 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.
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.
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.
- 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