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

DynamicPDF Generator Information

More information on DynamicPDF Generator can be found from its webpage.

Available on Other Platforms

DynamicPDF Generator is also available for the .NET and Java 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!