Loading Encrypted Files Using the Documents Library

Some documents formats such as PDF, support optional encryption and require being decrypted with a password before they can be used.

When using the DocumentFactory to load such documents, a Document object is created and returned as usual. However it will be encrypted and unusable till the correct password is applied to decrypt it. Unusable means only the information properties of the document are available (such as its DocumentId, DocumentType and MimeType), but the Pages collection will be empty and cannot interact with the document by getting any more information from it.

Two ways to pass the password phrase used to decrypt a document:

  1. Setting the password in the LoadDocumentOptions.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 and is loaded using DocumentFactory.LoadFromUri, then it will be downloaded to the cache or a temporary file before having the password applied.

    If the password is wrong, an exception will be thrown and the document will be deleted.

    Retrying with another password requires the application to call DocumentFactory.LoadFromUri again and repeating the whole process which is non-optimal solution.

  2. Calling the DocumentFactory.LoadFromUri with LoadDocumentOptions.Password is set to null. A Document will be returned with the following property values:

    Document.IsEncrypted is set to true (it is encrypted).Document.IsDecrypted is 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 Document.Decrypt with the password as many times as needed while checking the Document.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 Document.IsEncrypted

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Imaging, Medical, and Document