出现蓝色框而不是数字签名,并且签名面板包含未签名的签名

问题描述 投票:0回答:1

我正在使用 pdfbox 库来添加签名。

我正在尝试在 pdf 中附加数字签名并使用 Notarius 证书颁发机构验证它。当我尝试在 pdf 中附加证书并在 adobe acrobat 中打开它时,屏幕上出现蓝色框而不是签名图像。另外,如果我打开此 pdf 的签名面板,则表明 pdf 已通过认证,但它包含三个未签名的签名字段(因为我们在 pdf 中有三个签名)。获得蓝框的原因应该是什么? 我希望我的签名在 adobe acrobat pdf reader 中可见并具有经过验证的状态。

附上一些图片供您参考。 Signed pdf Signature panel for the same signed pdf file

请下载签名的 pdf 并在 adobe acrobat 中打开

我已经给出了用于在 pdf 中插入符号的代码。

    private void addSignatureField(PdfField pdfField,PDDocument document,PDAcroForm pdfForm,File signImage,PrintLocation printLocation) throws Exception
   {
      PDRectangle rectangle = signatureFieldRectangle(document.getPage(0),pdfField,printLocation);
      PDPage pdPage = document.getPage(pdfField.getPage());
      List<PDField> pdfFormFields = pdfForm.getFields();
      PDSignatureField signatureField = new PDSignatureField(pdfForm);
      signatureField.setPartialName(pdfField.getName());
      PDAnnotationWidget widget = signatureField.getWidgets().get(0);
      pdfFormFields.add(signatureField);
      widget.setRectangle(rectangle);
      widget.setPage(pdPage);
      PDStream stream = new PDStream(document);
      PDFormXObject form = new PDFormXObject(stream);
      form.setResources(new PDResources());
      form.setFormType(1);
      PDRectangle bbox = new PDRectangle(rectangle.getWidth(), rectangle.getHeight());
      form.setBBox(bbox);

      PDAppearanceDictionary appearance = new PDAppearanceDictionary();
      appearance.getCOSObject().setDirect(true);
      PDAppearanceStream appearanceStream = new PDAppearanceStream(form.getCOSObject());
      appearance.setNormalAppearance(appearanceStream);
      widget.setAppearance(appearance);

      try (PDPageContentStream cs = new PDPageContentStream(document,appearanceStream))
      {
         cs.setNonStrokingColor(Color.white);
         cs.addRect(-5000, -5000, 10000, 10000);
         cs.fill();
         if (signImage != null) {
            cs.saveGraphicsState();
            cs.transform(Matrix.getScaleInstance(0.25f, 0.25f));
            PDImageXObject img = PDImageXObject.createFromFileByExtension(signImage, document);
            cs.drawImage(img, 0, 0);
            cs.restoreGraphicsState();
         }
      }
      pdPage.getAnnotations().add(widget);
      COSDictionary pageTreeObject = pdPage.getCOSObject();
      while (pageTreeObject != null) {
         pageTreeObject.setNeedToBeUpdated(true);
         pageTreeObject = (COSDictionary) pageTreeObject.getDictionaryObject(COSName.PARENT);
      }
   }
java spring-boot pdfbox digital-signature acrobat
1个回答
0
投票

根据您的评论,您似乎尝试实现类似于 Adobe Acrobat Sign 常规工作流程的操作:所有“签名者”用户都提供一些墨水签名图像,只有签名服务应用实际的数字签名。

您的实现使用签名字段将这些墨迹签名图像放入 PDF 中,最后添加唯一实际的数字签名作为作者签名。

错误

您的方法中的错误是您使用实际的签名表单字段作为墨水签名图像。签名表单字段是为数字签名(和时间戳)而设计的,而不是为简单的电子签名而设计的。

带有墨水签名图像的签名字段确实具有可视化效果(显示图像),但它们没有值(必须是带有 CMS 签名容器的签名字典)。因此,Acrobat(也像其他软件产品一样)假设这些签名字段尚未签名。

现在 Acrobat 具有以下功能(或怪癖?):以蓝色显示未签名的签名字段,并带有红色“在此签名”箭头,并忽略现有外观。

这说明你看到了

其他观众可能会以不同的方式处理这个问题。例如,Chrome 中的内置查看器会显示您的墨迹签名图像:

修复

作为修复,不要将签名字段用于简单的电子签名,而仅用于数字签名。

显示这些墨水签名图像的替代选项包括:

  • 将这些图像添加到静态页面内容中;
  • 添加这些图像作为一些通用的非小部件注释的外观;
  • 添加这些图像作为(非活动)按钮的外观。
© www.soinside.com 2019 - 2024. All rights reserved.