isEncrypted Property

Summary

Gets a value that indicates whether this document is encrypted.

Syntax
TypeScript
JavaScript
Object.defineProperty(LEADDocument.prototype, 'isEncrypted', 
   get: function() 
) 
readonly isEncrypted: boolean; 

Property Value

true if this document is encrypted; otherwise, false.

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

This example will load an encrypted document, show that it is encrypted, and make the call to decrypt it.

Start with the example from LEADDocument and replace all the code inside the example function (search for the "// TODO: add example code here" comment) with the following code:

TypeScript
JavaScript
// Assume that this document is encrypted with a password. 
var url = "https://demo.leadtools.com/images/pdf/encrypted.pdf"; 
var password = "password"; 
var loadDocumentOptions = new lt.Document.LoadDocumentOptions(); 
// Note: That you can set the password directory here into loadDocumentOptions.password and the document will be decrypted 
// automatically by the service. This example assumes that the password is not known in advance and will be obtained from the 
// user. 
lt.Document.DocumentFactory.loadFromUri(url, loadDocumentOptions) 
   .done(function (doc) { 
      log("Document loaded...", doc); 
      if (doc.isEncrypted && !doc.isDecrypted) { 
         // We need to decrypt it before we can use it 
         log("Document is encrypted. Number of pages will be incorrect: " + doc.pages.count); 
         log("Decrypting..."); 
         doc.decrypt(password) 
            .done(function (document) { 
               log("Document is now decrypted. Number of pages: " + doc.pages.count); 
            }) 
            .fail(showServiceError) 
            .always(function () { 
               log("Complete."); 
            }); 
      } 
      else { 
         log("Document is not encrypted. Number of pages: " + doc.pages.count); 
      } 
   }) 
   .fail(showServiceError); 
class LEADDocument_IsEncryptedExample { 
    public constructor() { 
        lt.RasterSupport.setLicenseUri("https://demo.leadtools.com/licenses/v200/LEADTOOLSEVAL.txt", "EVAL", null); 
    } 
 
    public run(buttonID: string) { 
        document.getElementById(buttonID).onclick = this.isEncrypted; 
    } 
 
    /** 
     * Checks a LEADDocument to see if it is encrypted. 
     * We will assume that the document being loaded is encrypted with a password. 
     */ 
    isEncrypted = () => { 
        const url = "https://demo.leadtools.com/images/pdf/leadtools.pdf"; 
        const password = "password"; 
        const loadDocumentOptions = new lt.Document.LoadDocumentOptions(); 
 
        // Note: That you can set the password directory here into loadDocumentOptions.password and the document will be decrypted 
        // automatically by the service. This example assumes that the password is not known in advance and will be obtained from the 
        // user. 
 
        lt.Document.DocumentFactory.loadFromUri(url, loadDocumentOptions) 
            .done((document: lt.Document.LEADDocument) => { 
                log("Document loaded...", document); 
                if(document.isEncrypted && !document.isDecrypted) { 
                    // We need to decrypt it before we can use it 
                    log("Document is encrypted. Number of pages will be incorrect: " + document.pages.count); 
                    log("Decrypting..."); 
                    document.decrypt(password) 
                        .done((document: lt.Document.LEADDocument) => { 
                            log("Document is now decrypted. Number of pages: " + document.pages.count); 
                        }) 
                        .fail(showServiceError) 
                        .always(()=>{ 
                            log("Complete."); 
                        }); 
                } 
 
            }) 
            .fail(showServiceError); 
    } 
} 

Requirements

Target Platforms

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

Leadtools.Document Assembly