Loading Encrypted Files Using the Documents Library

Summary

Some document file types support optional encryption and require being decrypted with a password before they can be used. PDF is an example of such documents.

When you use the LoadFromUri or LoadFromCache methods to load these documents, a Document object is created and returned as usual. It will, however, be encrypted and unusable until the correct password is applied to decrypt it. Unusable means only the information properties of the document are available (such as its DocumentId and MimeType), but the Pages collection will be empty and you cannot interact with the document by getting any more information from it.

There are two ways to pass the password phrase used to decrypt this document:

  • Set the password in the Password property. This is the easiest way but requires the correct password to be available before the document is loaded. If the document is in a remote location (not in the cache) and is loaded using LoadFromUri then it will be downloaded to the cache or a temporary file before having the password applied. And if the password is wrong, an exception will be thrown and the document is deleted. Retrying with another password requires the application to call LoadFromUri again and repeating the whole process which is not a good solution in this case.

  • Instead of setting the password before the document is added to the cache, leave Password as null. This will return a Document as usual but will have the IsEncrypted value set to true (it is encrypted) and IsDecrypted value set to false (it has not been decrypted).

    The application can check for this value and then prompt the user for the password phrase. It can then call Decrypt with the password as many times as needed while checking the IsDecrypted property. When this property becomes true, it means the correct password was applied and the document is unlocked and ready to use.

    For an example, refer to IsEncrypted

Help Version 20.0.2018.3.5
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS HTML5 JavaScript