←Select platform

PDFSecurityOptions Class

Summary
PDF security and encryption options.
Syntax
C#
VB
C++
Java
[SerializableAttribute()] 
public class PDFSecurityOptions 
<SerializableAttribute()> 
Public Class PDFSecurityOptions  
public class PDFSecurityOptions 
[SerializableAttribute()] 
public ref class PDFSecurityOptions  
Remarks

The PDFSecurityOptions class is used as the type for the SecurityOptions and used to read and write the security and encryption options to use with PDF files.

When reading PDF documents, PDFDocument.SecurityOptions will always be populated automatically when the PDFDocument object is initialized.

When writing PDF documents, the following methods of the PDFFile class will use the security options set in PDFFile.SecurityOptions when updating or created a PDF file:

If the value of PDFFile.SecurityOptions is null, then the PDFFile will not encrypt the result PDF file.

User Password and Owner Password

There are two different types of passwords to protect different aspects of a PDF file with a password:

  • By using a user password set in UserPassword external viewers such as Adobe Acrobat will ask the user for the same password when opening the file for viewing. If the correct password is supplied, then the PDF is opened for viewing.

  • By using an owner password set in OwnerPassword external viewers such as Adobe Acrobat will disallow certain operations on the PDF file such as printing or editing. These operations can be re-enabled by editing the PDF's security options and supplying the owner password.

Example
C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
using Leadtools.WinForms; 
 
 
/// This example will encrypt a PDF file with both a user password and an owner password and restrict printing. 
 
public void PDFFileSecurityOptionsExample() 
{ 
   string sourceFileName = Path.Combine(LEAD_VARS.ImagesDir, @"Leadtools.pdf"); 
   string destinationFileName = Path.Combine(LEAD_VARS.ImagesDir, @"LEAD_EncryptedNoPrint.pdf"); 
 
   PDFFile pdfFile = new PDFFile(sourceFileName); 
 
   // Set the security options 
   pdfFile.SecurityOptions = new PDFSecurityOptions(); 
   pdfFile.SecurityOptions.UserPassword = "LEAD"; 
   pdfFile.SecurityOptions.OwnerPassword = "LEAD_SECRET"; 
   pdfFile.SecurityOptions.PrintEnabled = false; 
   pdfFile.SecurityOptions.HighQualityPrintEnabled = false; 
   pdfFile.SecurityOptions.EncryptionMode = PDFEncryptionMode.RC128Bit; 
 
   // Encrypt the file by saving it to the destination file 
   pdfFile.Convert(1, -1, destinationFileName); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Pdf 
Imports Leadtools.WinForms 
Imports Leadtools.Svg 
Imports Leadtools.ImageProcessing 
 
''' This example will encrypt a PDF file with both a user password and an owner password and restrict printing. 
 
Public Sub PDFFileSecurityOptionsExample() 
   Dim sourceFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf") 
   Dim destinationFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "LEAD_EncryptedNoPrint.pdf") 
 
   Dim pdfFile As PDFFile = New PDFFile(sourceFileName) 
 
   ' Set the security options 
   pdfFile.SecurityOptions = New PDFSecurityOptions() 
   pdfFile.SecurityOptions.UserPassword = "LEAD" 
   pdfFile.SecurityOptions.OwnerPassword = "LEAD_SECRET" 
   pdfFile.SecurityOptions.PrintEnabled = False 
   pdfFile.SecurityOptions.HighQualityPrintEnabled = False 
   pdfFile.SecurityOptions.EncryptionMode = PDFEncryptionMode.RC128Bit 
 
   ' Encrypt the file by saving it to the destination file 
   pdfFile.Convert(1, -1, destinationFileName) 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images" 
End Class 
Requirements

Target Platforms

Help Version 21.0.2021.7.6
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.