←Select platform

OwnerPassword Property

Summary

Owner password to use when encrypting a PDF file.

Syntax

C#
C++/CLI
Java
Python
public string OwnerPassword { get; set; } 
public String getOwnerPassword(); 
public void setOwnerPassword( 
   java.lang.String string 
); 
public: 
property String^ OwnerPassword { 
   String^ get(); 
   void set (    String^ ); 
} 
OwnerPassword # get and set (PDFSecurityOptions) 

Property Value

A System.String that contains the owner password to use when protecting a PDF file to disallow user access. The default value is null.

Remarks

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

Password Type Permissions
UserPassword Restricted by PDFSecurityOptions properties
OwnerPassword Full Access, PDFSecurityOptions properties do not restrict access

User Password

UserPassword protects with encryption and requires a valid password to open it. Use for restricting PDF file properties. UserPassword requires 128-bit encryption to provide the level of control available with the PDFSecurityOptions properties.

PDF viewers such as Adobe Acrobat will ask for the UserPassword if specified in a PDF file. Viewing the PDF file is only granted with a correct password value. To allow anyone to view the PDF file, do not set a value in UserPassword (leave it as an empty string or null).

Used to restrict certain rights on the PDF file when loading into a viewer such as Adobe Acrobat, these include but not limited to disabling printing the PDF file. When protecting a PDF file with a UserPassword you can control user access to PDF attributes:

Owner Password

OwnerPassword protects with encryption and requires a valid password to open it. OwnerPassword can open PDF files with no restrictions to the PDF attributes, even if restrictions are specified by PDFSecurityOptions. The file is encrypted either with 40- or 128-bit encryption.

Setting Both Passwords

In cases where both OwnerPassword and UserPassword are set on the same PDF file, consider the target audience and the kind of PDF file permissions and control that can be granted by each of the password options.

For both password options, opening and viewing the file with either password is possible. However, UserPassword provides another layer of file permissions to restrict certain properties even after opening the PDF file. UserPassword is able to block content editing, printing, copying, document assembly and other restrictions as set with PDFSecurityOptions. In the case of OwnerPassword, with the correct password a file is opened and viewed without restrictions.

Use Case: Readers versus Editors

In general, the target audience to use the UserPassword option, is an audience of readers and not editors. In the case of editors, the OwnerPassword option is best as it grants full permission rights. For comparison, two tables below show the PDFSecurityOptions properties setting access to a PDF file with both UserPassword and OwnerPassword passwords:

Case 1: Disabled PDFSecurityOptions Permissions

The OwnerPassword option provides full permission but the UserPassword option has restricted access.

PDFSecurityOptions Property Enabled UserPassword Permission OwnerPassword Permission
Annotations false
Assembling false
Copying text to the clipboard false
Editing false
Printing Quality false
Printing false

Case 2: Enabled PDFSecurityOptions Permissions

The OwnerPassword option provides full permission and the UserPassword option has gained additional permissions.

PDFSecurityOptions Property Enabled UserPassword Permission OwnerPassword Permission
Annotations true
Assembling true
Copying text to the clipboard true
Editing true
Printing Quality true
Printing true

Example

C#
using Leadtools.WinForms; 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
 
 
/// 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:\LEADTOOLS22\Resources\Images"; 
} 

Requirements

Target Platforms

See Also

PDFSecurityOptions Class

PDFSecurityOptions Members

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

Leadtools.Pdf Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.