0

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());

Jeff Schaller
  • 2,352
  • 5
  • 23
  • 38
Cemail Sn
  • 25
  • 4
  • 1
    What changes are allowed and what changes are not allowed to a signed PDF, depends on the existing signature. If changes are allowed at all, some uses of `PdfCanvas` are ok and some not. Unfortunately, you neither show how you create that `PdfCanvas` nor what you do with it, and you also don't mention the details of the first signature. Thus, please provide that information. Optimally, please also share an example PDF before and after applying your signature for analysis because sometimes there are weird tiny details of the original pdf that disallow adding another signature. – mkl Nov 29 '22 at 05:29
  • In your edit you show how you create and use `PdfCanvas`. You create it to work on the page content streams of the given page: `new PdfCanvas(signer.getDocument(), possitionResponse.getPageNumber())`. Indeed, this is considered to be a *change of page **content*** which is never allowed after signing. What may be allowed, is a change of the appearance of the signature widget annotation. – mkl Nov 30 '22 at 05:22

0 Answers0