使用 itext 用用户密码解密受保护的pdf。在控制台中显示为用法:
{{1}}
帮助我成为 itext
的新手答案 0 :(得分:0)
您可以参考此代码,它在我的情况下正常工作:
public class PDFUtils {
public static final String SOURCE_FILE = "encrypted.pdf";
public static final String DESTINATION_FILE = "decrypted.pdf";
public static void main(String[] args) throws IOException, DocumentException {
File file = new File(DESTINATION_FILE );
file.getParentFile().mkdirs();
new PDFUtils ().decryptPdf(SOURCE_FILE , DESTINATION_FILE );
}
public void decryptPdf(String srcFile, String destFile) throws IOException, DocumentException {
PdfReader reader = new PdfReader(srcFile, "XXX".getBytes());
System.out.println(new String(reader.computeUserPassword()));
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(destfile));
stamper.close();
reader.close();
}
}