我正在尝试读取 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
-Ff
标志 here .
最佳答案
在这个过程中我还需要保存文档。 所以 pdDoc.save("新文件的路径"); -> 为我工作,签名字段被禁用。
关于java - Apache PDFBox 禁用签名字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29018839/