检验上传文件是否加密
在这里插入代码片
```import com.itextpdf.text.exceptions.BadPasswordException;
import com.itextpdf.text.pdf.PdfReader;
public class PdfEncryptionChecker {
public static void main(String[] args) {
try {
PdfReader reader = new PdfReader("F:\\材料\\IE\\ceshi.pdf");
if (!reader.isOpenedWithFullPermissions())
throw new IllegalArgumentException();
} catch (BadPasswordException e) {
System.out.println("PDF is password protected..");
} catch (IllegalArgumentException e) {
System.out.println("pdfreader.not.opened.with.owner.password");
}catch (Exception e) {
e.printStackTrace();
}
}
public static boolean CheckPDF(String filePath){
try {
PdfReader reader = new PdfReader(filePath);
if (!reader.isOpenedWithFullPermissions())
throw new IllegalArgumentException();
} catch (BadPasswordException e) {
return false;
} catch (IllegalArgumentException e) {
return false;
}catch (Exception e) {
e.printStackTrace();
}
return true;
}
}