java Apache PDFBox禁用签名字段
我正在尝试读取PDF文件,然后在此过程中禁用签名字段
PDDocument pdDoc = null;
try {
final int FLAG_READ_ONLY = 1;
File file = new File("C:/sample.pdf");
InputStream is = new FileInputStream(file);
pdDoc = PDDocument.load(is);
PDDocumentCatalog catalog = pdDoc.getDocumentCatalog();
PDAcroForm form = catalog.getAcroForm();
List<PDField> acroFormFields = form.getFields();
for (PDField field: acroFormFields) {
if (field.getFieldType().equalsIgnoreCase("Sig")) {
field.getFullyQualifiedName();
field.setReadonly(true);
field.getDictionary().setInt("FF", FLAG_READ_ONLY);
}
}
if (pdDoc != null) {
pdDoc.close();
}
}
我的问题是:
- 我如何知道这是否有效?因为,当我打开 PDF我仍然可以在文件上签名李>
field.getDictionary().setInt("FF", FLAG_READ_ONLY);
我没有看到标志值Ff
,所以应该使用哪个标志。文档中说FLAG_READ_ONLY
-aFf
标志here李>
# 1 楼答案
在这个过程中,我还需要保存文档。 所以pdDoc。保存(“新文件的路径”)->;为我工作,签名字段被禁用