Am 26.12.2016 um 14:03 schrieb Maxime GUERREIRO:
Assuming "isEncrypted" throws the exception, do I need to create
another PDDocument instance?
The exception is thrown by load(), not by isEncrypted(), if the password
is incorrect.
Yes, you'd need to recall load() with the correct password.
If it is encrypted and the empty password was correct then you're ready
and don't have to call again.
sample code in PDFDebugger:
private void parseDocument( File file, String password )throws
IOException
{
while (true)
{
try
{
document = PDDocument.load(file, password);
}
catch (InvalidPasswordException ipe)
{
//
https://stackoverflow.com/questions/8881213/joptionpane-to-get-password
JPanel panel = new JPanel();
JLabel label = new JLabel("Password:");
JPasswordField pass = new JPasswordField(10);
panel.add(label);
panel.add(pass);
String[] options = new String[] {"OK", "Cancel"};
int option = JOptionPane.showOptionDialog(null, panel,
"Enter password",
JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, "");
if (option == 0)
{
password = new String(pass.getPassword());
continue;
}
throw ipe;
}
break;
}
If so, is there a way for me to prevent the memory/tempfile
consumption caused by the first (useless) instance?
No.
Tilman
Thanks,
Maxime
PS/ Thanks for the empty password tip, I was not aware of this
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]