PDF/A signed with iText 7 fails VeraPDF 1b validation

310 Views Asked by At

I'm evaluating iText 7.2.2 for signing PDF/A (1b/2b/3b) documents. Currently using a self-signed certificate (which may change to a "official" one sometime in the future) but that probably isn't relevant to the issue I'm encountering with validation. The PDF/A-1b documents in question are generated by a Documentum service that runs Ghostscript under the covers. The PDF/A-1b document passes VeraPDF validation. However, after signing it with iText (code follows), the validation fails with:

VeraPDF PDF/A-1b Validation Report

Code:

Certificate[] chain = ks.getCertificateChain(alias);
PdfReader reader = new PdfReader(src);
PdfSigner signer = new PdfSigner(reader, new FileOutputStream(dest), new StampingProperties());

IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256, new BouncyCastleProvider().getName());
IExternalDigest digest = new BouncyCastleDigest();

// Sign the document using the detached mode, CMS or CAdES equivalent.
signer.signDetached(digest, pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CMS);

I'm assuming that the "form field" is referring to the signature. So I'm not sure what to do to fix the lack of an "appearance dictionary" for what, as the code shows, is essentially an invisible signature.

FYI, the code used for signing is based on this iText KB

1

There are 1 best solutions below

1
On

The validator is complaining about the absence of the signature form field appearance. To add your signature form field appearance, you can use the convenient builder that PdfSigner provides:

signer.setFieldName("signature");
signer.getSignatureAppearance()
        .setPageRect(rect)
        .setReasonCaption(line)
        .setLayer2Font(font)
        .setLayer2Text("Hello, iText");

Make sure to build the appearance before calling signDetached