有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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();
    }
} 

我的问题是:

  1. 我如何知道这是否有效?因为,当我打开 PDF我仍然可以在文件上签名
  2. field.getDictionary().setInt("FF", FLAG_READ_ONLY);我没有看到标志值Ff,所以应该使用哪个标志。文档中说FLAG_READ_ONLY-aFf标志here

共 (1) 个答案

  1. # 1 楼答案

    在这个过程中,我还需要保存文档。 所以pdDoc。保存(“新文件的路径”)->;为我工作,签名字段被禁用