This page describes how to perform indexing of password protected documents.
Indexing using the password dictionary
To perform indexing of password protected documents using a password dictionary, you must add passwords for all protected documents to the dictionary before indexing. To add a document password to the dictionary, you must specify the full path to the document (or the document key for a document added from a stream) as a key, for example, a path returned by os.path.abspath, and the actual password to the document. The password dictionary can be changed at any time. For more information about managing the password dictionary see the Document passwords page in the Managing dictionaries section.
The password dictionary is stored on disk in encrypted form. However, very simple encryption is used, so if you want to protect the passwords themselves, it is better to use the password_required event to set passwords.
The following example demonstrates how to perform indexing of password protected documents using a password dictionary.
importosfromgroupdocs.searchimportIndex# Creating an indexindex=Index("./index")# Adding document passwords to the dictionary# (an index opened again keeps its dictionary, so the password may be there already)key=os.path.abspath("./documents/ProtectedDocument.docx")ifnotindex.dictionaries.document_passwords.contains(key):index.dictionaries.document_passwords.add(key,"123456")# ...# Indexing documents from the specified folder# Passwords will be automatically retrieved from the dictionary when necessaryindex.add("./documents")result=index.search("strikethrough")print("Documents found:",result.document_count)
The password for the protected document can also be provided when the password_required event occurs. This method is more secure; however, it requires matching the indexed documents and their passwords in the event handler.
Both of the described methods for providing document passwords can be used together. The index first checks for a document password in the password dictionary, and then, if the password is absent, raises the password_required event. If the password is not provided or an incorrect password is provided, the index will raise the error_occurred event with the corresponding error message and the document will not be indexed. You can learn more about index events on the page Search index events.
The handler of the event receives the sender and the event arguments, and sets the password property of the arguments. The following example shows how to provide password for a document using the password_required event.
fromgroupdocs.searchimportIndex# Creating an indexindex=Index("./index")# Subscribing to the eventdefon_password_required(sender,args):ifargs.document_full_path.lower().endswith("protecteddocument.docx"):args.password="123456"# Providing password for the file 'ProtectedDocument.docx'index.events.password_required+=on_password_required# Indexing documents from the specified folderindex.add("./documents")result=index.search("strikethrough")print("Documents found:",result.document_count)
Along with the full-featured library, we provide a free online document search app. You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our Free Online Document Search App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.