PDFBox - 签名 PDF 已由另一个人签名

PDFBox - sign PDF have existing signed by another

正在尝试对已使用 PDFBox 签名的现有 PDF 签名

具有此测试功能:

/**
     * Test creating visual signature with the modernized example.
     *
     * @throws IOException
     * @throws CMSException
     * @throws OperatorCreationException
     * @throws GeneralSecurityException
     * @throws TSPException
     * @throws CertificateVerificationException
     */
    @ParameterizedTest
    @MethodSource("signingTypes")
    void testCreateVisibleSignature2(boolean externallySign)
            throws IOException, CMSException, OperatorCreationException, GeneralSecurityException,
                   TSPException, CertificateVerificationException
    {
        // sign PDF
        String inPath = IN_DIR + "pdf.pdf";
        File destFile;

        CreateVisibleSignature2 signing = new CreateVisibleSignature2(keyStore, PASSWORD.toCharArray());
        Rectangle2D humanRect = new Rectangle2D.Float(200, 300, 200, 100);
        signing.setImageFile(new File(JPEG_PATH));

        signing.setExternalSigning(externallySign);
        destFile = new File(OUT_DIR + getOutputFileName("Signed.pdf", externallySign));
        signing.signPDF(new File(inPath), destFile, humanRect, tsa);

        checkSignature(new File(inPath), destFile, false);
    }

当尝试设置 MDPPermission 进程时:

if (doc.getVersion() >= 1.5f && accessPermissions == 0)
            {
                SigUtils.setMDPPermission(doc, signature, 2);
            }



 if (sig.getCOSObject().containsKey(COSName.CONTENTS))
            {
                throw new IOException("DocMDP transform method not allowed if an approval signature exists");
            }

但是在这个函数上 SigUtils 出错了:

java.io.IOException: DocMDP transform method not allowed if an approval signature exists

我怎样才能将文件传递给签名?

错误消息“如果存在批准签名则不允许使用 DocMDP 转换方法”是正确的。

如果您想为已签名的 PDF 添加签名,只需删除

if (doc.getVersion() >= 1.5f && accessPermissions == 0)
{
    SigUtils.setMDPPermission(doc, signature, 2);
}

阻止。