Password Protect PDF in COM/ActiveX

Password protection can be added to new PDF documents or to an existing PDF document using the DynamicPDF Generator and Merger products respectively. The steps and sample codes below explains using both products.

How to Password Protect a PDF

Setting password protection and encrypting a PDF can be done in a few lines of code.

When a user password is specified, the PDF viewer will require this password to open the PDF document. If left blank the viewer will not prompt for a password when opening the PDF.

When an owner password is specified, the PDF viewer will require it to modify the PDF.

Below is the list of classes used to set passwords or to encrypt PDF with different secuirty settings.

Steps to Password Protect PDF

  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 security to the Document.
  5. Output the Document 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 a PDF

The above security classes can be used to add password protection to an existing PDF document as well.

Steps to Add Password to PDF

  1. Create a Document object and Load the PDF file.
  2. Create a Aes256Security object by setting the owner and user password.
  3. Set the security to the Document.
  4. Output the Document 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 and Merger Information

More information can be found here:

Available in Other Platforms

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

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