I have to create a function that tells me is an uploaded PDF file encrypted-only, timestamped-only, none, or both. So far I am using PDFBox 2.0.5 and only success knowing timestamped-only and none file.
Here is the current code:
try{
InputStream fis = new ByteArrayInputStream(file.getBytes());
PDDocument d = PDDodument.load(fis); //encrypted file will go to InvalidPasswordException error
//***file not encrypted***
List<PDSignature> a = d.getSignatureDictionaries();
List<PDSignatureField> b = d.getSignatureFields();
if(a.size()==0 && b.size()==0){
//***file not timestamped***
}else{
//***file timestamped***
}
} catch(InvalidPasswordException e){
//***file encrypted***
//***is file timestamped?***
//***is file not timestamped?***
} catch(IOException e){
}
My question is, how to know if there any timestamp (as signature) on encrypted pdf file?
Note: I have found several PDFBox usage example but rarely find PDFBox latest version implemented example
Update note: file is an uploaded MultipartFile object, having hard time getting its path avoiding copying or transferring it into another object type