←Select platform

Password Property

Summary
Gets or sets the password associated with this PDFFile.
Syntax
C#
VB
C++
Java
public string Password { get; set; } 
Public Property Password As String 
public String getPassword(); 
public void setPassword( 
   java.lang.String string 
); 
public: 
property String^ Password { 
   String^ get(); 
   void set (    String^ ); 
} 

Property Value

A System.String that contains the password to use when loading this PDFFile object (if the file is encrypted).

Remarks

You can also set the password directly when creating a PDFFile object by calling the PDFFile(string fileName, string password) constructor.

Some PDF files are encrypted and require a password before they can be used. Encrypted files must have the Password property set to the correct value before using the other properties and methods of the object. Use IsEncrypted to determine whether the PDF file is encrypted and requires a password.

After setting the filename (and optional password), call the Load method to populate the PDFFile object's DocumentProperties and Pages properties with the correct values. Or use any of the other file feature functions supported by this class.

PDF file passwords can be no more than 64 ASCII characters. LEADTOOLS will automatically truncate and convert the password string to ASCII if necessary. Set the maximum password length by setting the PDFDocument.MaximumPasswordLength constant.

Example
C#
VB
using Leadtools.WinForms; 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
 
 
public void PDFFileEncryptedExample() 
{ 
   string pdfFileName1 = Path.Combine(LEAD_VARS.ImagesDir, @"Leadtools.pdf"); 
   string pdfFileName2 = Path.Combine(LEAD_VARS.ImagesDir, @"Encrypted.pdf"); 
 
   // Create an encrypted version of Leadtools.pdf 
   PDFFile file = new PDFFile(pdfFileName1); 
   file.SecurityOptions = new PDFSecurityOptions(); 
   file.SecurityOptions.UserPassword = "LEAD"; 
   file.Convert(1, -1, pdfFileName2); 
 
   // Now try to open it as a document 
   string password = null; 
 
   if (PDFFile.IsEncrypted(pdfFileName2)) 
   { 
      Console.WriteLine("{0}\nIs encrypted. Enter the password:", pdfFileName2); 
      password = Console.ReadLine(); 
   } 
 
   // If the user entered the correct password (LEAD), you can open the file now 
   try 
   { 
      file = new PDFFile(pdfFileName2, password); 
      file.Load(); 
 
      PDFDocumentProperties props = file.DocumentProperties; 
 
      Console.WriteLine("  Title: {0}", props.Title); 
      Console.WriteLine("  Author: {0}", props.Author); 
      Console.WriteLine("  Subject: {0}", props.Subject); 
      Console.WriteLine("  Keywords: {0}", props.Keywords); 
      Console.WriteLine("  Creator: {0}", props.Creator); 
      Console.WriteLine("  Producer: {0}", props.Producer); 
      Console.WriteLine("  Created: {0}", props.Created); 
      Console.WriteLine("  Modified: {0}", props.Modified); 
      Console.WriteLine("----------:"); 
   } 
   catch (Exception ex) 
   { 
      // Otherwise, you will get an error that the PDF file is corrupted 
      Console.WriteLine(ex.Message); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Pdf 
Imports Leadtools.WinForms 
Imports Leadtools.Svg 
Imports Leadtools.ImageProcessing 
Imports LeadtoolsPdfExamples.Leadtools.Examples 
 
Public Sub PDFFileEncryptedExample() 
   Dim pdfFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf") 
   Dim pdfFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Encrypted.pdf") 
 
   ' Create an encrypted version of Leadtools.pdf 
   Dim file As PDFFile = New PDFFile(pdfFileName1) 
   file.SecurityOptions = New PDFSecurityOptions() 
   file.SecurityOptions.UserPassword = "LEAD" 
   file.Convert(1, -1, pdfFileName2) 
 
   ' Now try to open it as a document 
   Dim password As String = Nothing 
 
   If PDFFile.IsEncrypted(pdfFileName2) Then 
      Console.WriteLine("{0}" & Constants.vbLf & "Is encrypted. Enter the password:", pdfFileName2) 
      password = Console.ReadLine() 
   End If 
 
   ' If the user entered the correct password (LEAD), you can open the file now 
   Try 
      file = New PDFFile(pdfFileName2, password) 
      file.Load() 
 
      Dim props As PDFDocumentProperties = file.DocumentProperties 
 
      Console.WriteLine("  Title: {0}", props.Title) 
      Console.WriteLine("  Author: {0}", props.Author) 
      Console.WriteLine("  Subject: {0}", props.Subject) 
      Console.WriteLine("  Keywords: {0}", props.Keywords) 
      Console.WriteLine("  Creator: {0}", props.Creator) 
      Console.WriteLine("  Producer: {0}", props.Producer) 
      Console.WriteLine("  Created: {0}", props.Created) 
      Console.WriteLine("  Modified: {0}", props.Modified) 
      Console.WriteLine("----------:") 
   Catch ex As Exception 
      ' Otherwise, you will get an error that the PDF file is corrupted 
      Console.WriteLine(ex.Message) 
   End Try 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\LEADTOOLS22\Resources\Images" 
End Class 
Requirements

Target Platforms

See Also

Reference

PDFFile Class

PDFFile Members

Help Version 22.0.2021.10.28
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.