0

I would like to update the PDF signature appearance after signing. A prototype is made using iTextshap and following Is it possible to change the appearance of the signature within the document after signing it?. It's working great.

However, I got troubles after moved to iText7. Lots of classes are not available in iText7. Could anyone able advise me how to do this in iText7?

dbc
  • 104,963
  • 20
  • 228
  • 340
Alex
  • 1
  • Why do you want to do this? Changing appearances after signing points into the direction of 'manipulation'. Except being a security researcher there is not reason of doing this... – Lonzak Nov 24 '21 at 23:33
  • Hi Lonzak, it is a business need for updating the apearance to provide actual signed details.. Since mkl's example can modify appearance without invaildate existing signatures, I think we still can doing this – Alex Nov 25 '21 at 04:43
  • What signed details? Why can't you create that appearance during signing? Sorry to be persistent - but it seems that you have taken the wrong approach. Using the append mode/incremental update it is possible to add information after signing BUT manufacturers like *dobe forbid / or will forbid certain kind of changes. And replacing signature appearances suits that category imho. I mean when you compare it with a handwritten signature - what valid (legal) reason is there to change the appearance? – Lonzak Nov 25 '21 at 08:26
  • Hi Lonzak, I would like to add the signer name on the appearance. In my business situation, I don't know who will sign on the pdf. Change signature appearance do not invalidate the *dobe signature verification until now..For deferred signature there is signer public cert embeded into pdf, it can be the proven for legal rather than the appearance. – Alex Nov 26 '21 at 01:21
  • For reference, create itext's deferred signature procedure. 1. Create empty signature; 2. Create digest of pdf; 3. Send the digest to signer; 4 signer sign on the digest and send it back to issuer; 5. Issuer replace empty signature to signed digest.. – Alex Nov 26 '21 at 01:24
  • The deferred signature procedure you describe is correct. But it is like you said: `"[...] until now..."` - we don't know when it will stop working. But how about a process where a user when clicking on an empty signature field needs to input his name first and then sign? This could be implemented in many ways: a) Open a pop-up dialog and the user needs to input the name or b) add a mandatory textfield which needs to be filled [...]. Then you have all the information you need beforehand. This solution is much more future proof then later replacing the appearance... – Lonzak Nov 26 '21 at 08:07
  • @Lonzak I also think The need to update signature appearances after applying the signature indicates a bad architecture of the signing solution. But sometimes your application is doomed from the start, e.g. if you have both the requirement to put certificate details into the signature appearance and to support a signing service that creates a certificate just-in-time when processing the signing request. If you cannot discuss away one of those requirements, you have no choice but go for the bad architecture. – mkl Nov 26 '21 at 11:24
  • Agreed. But except for the hash itself the rest of the certificate is static (like issuer, serialnumber etc) and should be usable to create the appearance before actually signing. Depending on the type of certificate this changes only once a year (or even longer). Only exception which comes to mind would be adhoc-certificates. But in that case most(?) external signing provides (should) provide an additional API function where those infos can be acquired from before signing. – Lonzak Nov 26 '21 at 13:26
  • A business requirement, actual signed timestamp is also needed to append on signature appearance. The only way to do that is getting the time from signed hash(pkcs7) then update the empty signature appearance. I try to persuade user to check the time by clicking view signer certificate, but they actual want to know the signer and signed time after print it out – Alex Nov 27 '21 at 09:47
  • *Lots of classes are not available in iText7.* -- in that case, might you please [edit] your question to show the code that is not working? You're more likely to get an answer if you can show, concretely, what you have tried that does not work. For comparison, the [question to which you linked](https://stackoverflow.com/q/55964130/3744182) does show what they tried initially. See also [ask] and https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/ for additional tips on how to write a question here that's more likely to get a useful answer. – dbc Nov 28 '21 at 20:38
  • @Alex In the [answer you refer to](https://stackoverflow.com/a/56021333/1729265) I mentioned that the code there *essentially is a port of code from [this answer](https://stackoverflow.com/a/37070234/1729265) to C#.* That answer contains Java code both for iText 5 and iText 7. Taking the iText 7 code from that answer and porting it to C# should be pretty easy. – mkl Jan 25 '22 at 11:54
  • @mkl I read your answer and produced exact same result as your pdf with a warning. Then, I get back to use iTextSharp using your old [anwser](https://stackoverflow.com/questions/55964130/is-it-possible-to-change-the-appearance-of-the-signature-within-the-document-aft). It produces signed pdf without any warning. Do you have any idea how iTextSharp can escape from the verification? – Alex Feb 09 '22 at 08:03
  • Please share an example file, once processed by the iText 5 solution, one by the iText 7 solution. I can have a look... – mkl Feb 09 '22 at 11:46
  • Please have a look those [files](https://drive.google.com/file/d/1WmDcteQJqk7r3tRGRTFTxgFHZ8FMX05Z/view?usp=sharing). Thanks for the help – Alex Feb 10 '22 at 03:26
  • Ok, the difference is that the iText 5 based solution left the signature widget dimensions as they were while the iText 7 based one changed them. Let's have a look at the code... – mkl Feb 11 '22 at 10:49
  • Ok, the code in the [answer for iText 5 and 7 in Java](https://stackoverflow.com/a/37070234/1729265) and the first block of code in the [answer for iTextSharp](https://stackoverflow.com/a/56021333/1729265) changed the signature field **Rect** to a 100x100 square while the later code blocks in the [answer for iTextSharp](https://stackoverflow.com/a/56021333/1729265) left the **Rect** as it was and merely read it. Thus, please change your port of the iText 7 / Java code to also leave **Rect** as it is and merely read it... – mkl Feb 11 '22 at 11:07

0 Answers0