PdfCanvas invalid Signer in pdf used Itext 7

92 Views Asked by At

I am trying to add a border to a digital signature on a .pdf, however if more than one sign the first signature is invalidated and the second signature is valid, I suppose this happens because I am using PdfCanvas, for now I have not found another way to achieve it.

PdfSigner signer = new PdfSigner(pdfReader, byteNewPdf_2, new StampingProperties().useAppendMode());
PdfSignatureAppearance appearance = createAppearance(signer, reasonCert, reasonPDF, location,
                signBoxData, originalHashPdf, certData, metadata, pdfImage, idProcess, nameSigner,  signerNumber, signatureDate,  isDomain); 
Rectangle rect = signatureApp.appearanceRectangleSign(possitionResponse, metadata, signBoxData, signerNumber);
appearance.setPageRect(rect).setPageNumber(possitionResponse.getPageNumber());

IExternalDigest digest = new BouncyCastleDigest();
IExternalSignature signature = new PrivateKeySignature(pk, digestAlgorithm, provider);
signer.signDetached(digest, signature, chain, null, null,  null, 0 , subfilter);

I have read that the borders must be controlled with PdfCanvas, however I have the problem that the first signature is invalidated.

PdfCanvas canvas = signatureApp.borderSignPdf(signer, idProcess, signBoxData, possitionResponse,
               metadata, signerNumber);

In response to mkl's comment, I am sharing the fragment where the canvas is created, I make a return because it was generated within a method:

return new PdfCanvas(signer.getDocument(), possitionResponse.getPageNumber()) .rectangle(possitionResponse.getX(), possitionResponse.getY(), signBoxData.getSignatureBoxWidth(), signBoxData.getSignatureBoxHeight()) .setLineWidth(!view_BorderSign ? 0 : 1) .stroke();

The document is successfully signed with n signature numbers without a problem as long as the canvas is not placed, the signatures are not invalidated but as soon as I add the canvas the first signature is invalidated, maybe as they commented it is the way I create the signature.

PdfSigner signer = new PdfSigner(pdfReader, byteNewPdf_2, new
StampingProperties().useAppendMode());

0

There are 0 best solutions below