isEncrypted Property

Summary

Gets a value that indicates whether this document is encrypted.

Syntax

JavaScript Syntax
Object.defineProperty(Document.prototype, 'isEncrypted', 
	get: function() 
) 
TypeScript Syntax
isEncrypted: boolean; // read-only 

Property Value

true if this document is encrypted; otherwise, false.

Remarks

In most cases, the Document 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 Document 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 Documents Library.

Example

This example will show how to check for encrypted documents and how to decrypt them.

Start with the example in Document and replace the example function call to the function below.

JavaScript Example
function decryptDocumentExample() { 
   // Load a new document 
   // Assume that this document is encrypted with the password "leadtools" 
   var url = "https://demo.leadtools.com/images/pdf/leadtools_encrypted.pdf"; 
   var password = "leadtools"; 
   var loadDocumentOptions = new lt.Documents.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.Documents.DocumentFactory.loadFromUri(url, loadDocumentOptions) 
       .done(function (doc) { 
          console.log("Document was loaded succesfully from URI"); 
          if (doc.isEncrypted && !doc.isDecrypted) { 
             // We need to decrypt it before we can use it 
             doc.decrypt(password) 
                 .done(function (document) { 
                    console.log("Document is decrypted is " + document.isDecrypted + " now and can be used. Number of pages is " + document.pages.count); 
                 }) 
                 .fail(function (jqXHR, statusText, errorThrown) { 
                    showServiceError(jqXHR, statusText, errorThrown); 
                 }); 
          } 
          else { 
             console.log("Document is not encrypted, can be used right away. Number of pages is " + doc.pages.count); 
          } 
       }) 
       .fail(function (jqXHR, statusText, errorThrown) { 
          showServiceError(jqXHR, statusText, errorThrown); 
       }); 
} 

Requirements

Target Platforms

Help Version 19.0.2017.10.18
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Documents Assembly