←Select platform

Decrypt Method

Summary

Decrypt this document using the specified password.

Syntax
C#
C++/CLI
Java
Python
public bool Decrypt( 
   string password 
) 
public:  
   bool Decrypt( 
      String^ password 
   ) 
public boolean decrypt(String password) 
def Decrypt(self,password): 

Parameters

password

String containing the password phrase to decrypt this document.

Remarks

In most cases, the LEADDocument is ready to use after it has been obtained. However, some documents such as PDF can be encrypted and required a password before it can be parsed and used. Most of the properties and methods of LEADDocument will throw an error if the document has not been decrypted. IsEncrypted can be used to check if the document is encrypted and if so, Decrypt must be called with a password obtained from the user to unlock the document. When that happens, the value of IsDecrypted becomes true and the document is ready to be used. Note that IsEncrypted will stay true to indicate the original state of the document.

For more information, refer to Loading Encrypted Files Using the Document Library.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Document.Writer; 
 
using Leadtools.Document; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Ocr; 
using Leadtools.Barcode; 
using Leadtools.Document.Converter; 
 
public void DocumentIsEncryptedExample() 
{ 
   // This is the password for this encrypted document 
   string password = "lead"; 
 
   var options = new LoadDocumentOptions(); 
 
   using (var document = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "Protected.pdf"), options)) 
   { 
      if (document.IsEncrypted && !document.IsDecrypted) 
      { 
         Console.WriteLine("Encrypted Document, decrypting it..."); 
         // Decrypt it now 
         document.Decrypt("lead"); 
      } 
 
      // Should not be encrypted anymore 
      System.Diagnostics.Debug.Assert(!document.IsEncrypted); 
   } 
 
   // Or, set the password directly in the load options 
   options.Password = password; 
   using (var document = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "Protected.pdf"), options)) 
   { 
      // Should not be encrypted 
      System.Diagnostics.Debug.Assert(!document.IsEncrypted); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

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