Leadtools.Documents Namespace > Document Object : IsEncrypted Property |
get_isEncrypted();
Object.defineProperty('isEncrypted');
Type | Description |
---|---|
boolean | true if this document is encrypted; otherwise, false. |
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.
function decryptDocumentCommandExample() { // Load a new document // Assume that this document is encrypted with the password "leadtools" var url = "http://demo.leadtools.com/images/pdf/leadtools_encrypted.pdf"; lt.Documents.DocumentFactory.loadFromUri(url, null) .done(function (document) { console.log("Document was loaded succesfully"); // Check if its encrypted, if so, we cannot use it till we decrypt it if (document.isEncrypted && !document.isDecrypted) { // It is, decrypt it using the password document.decrypt("leadtools") .done(function (success) { if (success) { alert("Document is ready to use"); // Show the PDF image of the first page in a new tab window.open(document.pages[0].getSvgUrl()); } else { alert("Invalid password"); } }) .fail(function (jqXHR, statusText, errorThrown) { alert("Error decrypting document " + errorThrown); }); } }) .fail(function (jqXHR, statusText, errorThrown) { alert("Error loading document " + errorThrown); }); }