Reputation: 49
Given a pdf
file, is it possible to determine if that file is editable or not in Java? PDDocument.getCurrentAccessPermission().isReadOnly()
does not work.
Upvotes: 0
Views: 3166
Reputation: 18851
In the 1.8 versions, when using the "old" parser, you need to call openProtection()
first, because such files are "encrypted" with the empty password:
if (doc.isEncrypted()
{
doc.openProtection(new StandardDecryptionMaterial(""));
}
and then you can call
doc.getCurrentAccessPermission().isReadOnly()
or any other method from the AccessPermission
class.
Alternatively, load your PDF with the "new" non-sequential parser:
PDDocument doc = PDDocument.loadNonSeq(new File(...), null);
and then doc.getCurrentAccessPermission().isReadOnly()
can also be called.
Upvotes: 1