Examples

Password Protect PDF in COM/ActiveX

Before opening a PDF document, if a document is password protected then a PDF viewer will require a password before opening the PDF document. Password protection can be added to new PDF documents or to existing PDF document when using DynamicPDF Core Suite. The steps and sample codes below illustrates adding password protection to both situations.

How to Password Protect a PDF

Depending upon your desired security settings, DynamicPDF Core Suite supports the following different security algorithms.

Here we illustrate using Aes256Security in the following example.

Steps to Password Protect PDF

  1. Create a Document object.
  2. Create a Page object and add it to Document instance.
  3. Create a Aes256Security object and pass the owner and user password to the instance's constructor.
  4. Set the Document instance's security.
  5. Output the Document instance to the browser.

Sample code - ASP

Dim MyDocument
Set MyDocument = Server.CreateObject("DynamicPDF.Document")
            
Dim MyPage
Set MyPage = MyDocument.AddPage()
           
Dim MySecurity
Set MySecurity = MyDocument.SetAes256Security("owner", "user")

MyDocument.DrawToWeb

How to Add Password to Existing PDF

The above security classes were used to add password protection to a new PDF document. You can also add password protection to an existing PDF document, as the following example illustrates.

Steps to Add Password Protection to a PDF

  1. Create a Document object and load the PDF file.
  2. Create a Aes256Security object instance and in the constructor, set the owner and user password.
  3. Set the Document instance's security.
  4. Output the Document instance to the Browser.

Sample Code - ASP

Dim MyDocument
Set MyDocument = Server.CreateObject("DynamicPDF.Document")
MyDocument.LoadPdf Server.MapPath("pdf-a.pdf")

Dim MySecurity
Set MySecurity = MyDocument.SetAes256Security("owner", "user")

MyDocument.DrawToWeb

Getting Started

NuGet Package

DynamicPDF Core Suite 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 from NuGet.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

DynamicPDF Core Suite Information

More information on DynamicPDF Core Suite can be found from its webpage.

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 18 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

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