←Select platform

UserPassword Property

Summary
The user password to use when encrypting a PDF file.
Syntax
C#
VB
C++
Java
public string UserPassword { get; set; } 
Public Property UserPassword As String 
public String getUserPassword(); 
public void setUserPassword( 
   java.lang.String string 
); 
public: 
property String^ UserPassword { 
   String^ get(); 
   void set (    String^ ); 
} 

Property Value

A System.String that contain the user password to use when encrypting a PDF file. The default value is null.

Remarks

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

User Password

UserPassword protects with encryption and requires a valid password to open it. Use for PDF file viewing protection. PDF viewers such as Adobe Acrobat will ask for the UserPassword if specified in a PDF. 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 the UserPassword (leave it as an empty string or null).

Owner Password

OwnerPassword restricts access to the PDF attributes specified by the owner but no password is required to open it. The file is not encrypted. Used to restrict certain rights on the PDF file when loading into a view such as Adobe Acrobat, these include disabling print. When protecting a PDF file with an OwnerPassword you can control user access to PDF attributes:

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.