I'm trying to add more than one digital signature to the same file simultaneously, but the second one invalidates the first one, do I need to set any special parameters?
//Load a pdf document
PdfDocument doc = new PdfDocument();
doc.loadFromBytes(pdfBytes);
for (RequestDataSignatureModel value : signatures) {
String certPfxKey = "CERT_" + value.getCertKey().toString() + "_PFX";
String certPfxPasswordKey = "CERT_" + value.getCertKey().toString() + "_PFX_PASSWORD";
byte[] certPfxFile = GoogleCloudSecretHelper.accessSecret(
certPfxKey,
"latest"
).getPayload().getData().toByteArray();
String certPfxPassword = GoogleCloudSecretHelper.accessSecret(
certPfxPasswordKey,
"latest"
).getPayload().getData().toString("UTF-8");
//Load the certificate
PdfCertificate pdfCert = new PdfCertificate(certPfxFile, certPfxPassword);
//Create a PdfSignature object and specify its position and size
PdfSignature signature = new PdfSignature(doc, doc.getPages().get(0), pdfCert, value.getName());
Rectangle2D rect = new Rectangle2D.Float();
rect.setFrame(new Point2D.Float(
(value.getX().intValue() > 0) ? value.getX().floatValue() : (float) (doc.getPages().get(0).getActualSize().getWidth() + value.getX().doubleValue()),
(value.getY().intValue() > 0) ? value.getY().floatValue() : (float) (doc.getPages().get(0).getActualSize().getHeight() + value.getY().doubleValue())),
new Dimension(220, 50)
);
signature.setBounds(rect);
//Set the graphics mode
signature.setGraphicMode(GraphicMode.Sign_Image_And_Sign_Detail);
signature.setSignTextAlignment(SignTextAlignment.Left);
//Set the signature content
signature.setName("Digitalmente assinado por:\n" + value.getName() + "\n\n");
signature.setDistinguishedNameLabel("CNPJ: ");
signature.setDistinguishedName(value.getDocument() + "\n\n");
signature.setDateLabel(MessageFormat.format("Data: {0} \n\n\n", dateFormat.format(new Date())));
signature.setDate(null);
signature.setSignImageSource(
PdfImage.fromFile(
certImg.getPath()
)
);
signature.setSignImageLayout(SignImageLayout.Stretch);
//Set the signature font
signature.setSignDetailsFont(new PdfFont(PdfFontFamily.Helvetica, 7f, PdfFontStyle.Regular));
//Set the document permission
signature.setDocumentPermissions(PdfCertificationFlags.Forbid_Changes);
signature.setCertificated(true);
}
//Save to file
Path signedFilePath = Paths.get(tempDir.getPath() + fileSeparator + executionId + ".pdf");
File singedFile = signedFilePath.toFile();