To get the number of passwords in the dictionary, use the getCount method.
To get the password for a document from the dictionary, the getPassword method is used, passing the path to the document as an argument.
The clear method is used to remove all passwords from the dictionary.
To check for the presence of a password in the dictionary for the specified document, the contains method is used.
To add a password to the dictionary, use the add method. The key is the path to the document.
To remove a password from the dictionary, use the remove method.
The following example demonstrates the use of methods of the password dictionary.
StringindexFolder="c:\\MyIndex\\";// Creating an index from in specified folder
Indexindex=newIndex(indexFolder);if(index.getDictionaries().getDocumentPasswords().getCount()>0){// Removing all passwords from the dictionary
index.getDictionaries().getDocumentPasswords().clear();}Stringpath=newFile("c:\\MyIndex\\Protected.pdf").getAbsolutePath();if(index.getDictionaries().getDocumentPasswords().contains(path)){// Getting a password for a document
Stringpassword=index.getDictionaries().getDocumentPasswords().getPassword(path);System.out.println(path);System.out.println("\tPassword: "+password);// Deleting the password from the dictionary
index.getDictionaries().getDocumentPasswords().remove(path);}// Adding a password for a document
index.getDictionaries().getDocumentPasswords().add(path,"123456");
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: