【问题标题】:Apache PDFBox Disable a signature fieldApache PDFBox 禁用签名字段
【发布时间】:2015-05-15 03:28:07
【问题描述】:

我正在尝试读取 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 - 一个Ff 标志here。

【问题讨论】:

    标签: java pdfbox


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2016-05-28
      • 1970-01-01
      • 2021-10-28
      • 1970-01-01
      相关资源
      最近更新 更多