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
- Create a
Document
object. - Create a
Page
object and add it toDocument
instance. - Create a
Aes256Security
object and pass the owner and user password to the instance's constructor. - Set the Document instance's security.
- 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
- Create a
Document
object and load the PDF file. - Create a
Aes256Security
object instance and in the constructor, set the owner and user password. - Set the Document instance's security.
- 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.
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.
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX