2

How to remove validity unknown icon(question mark) from signature field before calculating the hash of pdf.

Below code that I am using to create signature field.

PdfStamper stamper = PdfStamper.CreateSignature(reader, os, '\0');
PdfSignatureAppearance appearance = stamper.SignatureAppearance;
appearance.SignDate = DateTime.Now.AddMinutes(15);
appearance.Reason = reasonForSign;
appearance.Contact = "";
appearance.Location = locationToShowOnSignatureStamp;
appearance.Acro6Layers = false;
appearance.Image = null;
appearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.DESCRIPTION;
appearance.CertificationLevel = PdfSignatureAppearance.NOT_CERTIFIED;
appearance.SetVisibleSignature(new iTextSharp.text.Rectangle(10, 10, 149, 69), reader.NumberOfPages, "s1");

mkl
  • 90,588
  • 15
  • 125
  • 265
Mannan Bahelim
  • 1,289
  • 1
  • 11
  • 31

1 Answers1

4

Your code explicitly requests that icon: you use

appearance.Acro6Layers = false;

This instructs itext to create signature appearances as Adobe Acrobat up to version 5 did. This includes "layers" for signatures with positive, inconclusive, or negative validation results. If you use

appearance.Acro6Layers = true;

instead (which is the default), itext creates signatures for which Adobe Acrobat won't show such on-page visualizations of the validation result anymore.

mkl
  • 90,588
  • 15
  • 125
  • 265
  • Thanks it's working. I'm referring this pdf for Itextsharp. "Windows Developer Power Tools by Jim Holmes, James Avery". Can you tell me which document you are referring for Digital Signature using itextsharp C#. – Mannan Bahelim Apr 25 '19 at 06:39
  • 1
    @Mannan considering that that book is from 2007, chances are that it is a bit out of date. As you use itext before version 7, you might be interested in the white paper [Digital signatures for PDF Documents](https://itextpdf.com/de/resources/books/digital-signatures-pdf/intro). The paper is using java examples but you can find c# versions of them [here](https://git.itextsupport.com/projects/I5NS/repos/tutorial/browse/signatures). – mkl Apr 25 '19 at 09:05
  • @mkl, How to removed these signature validity symbol,after pdf is signed. Can it be done using pdfreader ? – Urmi_VV_Developer May 27 '20 at 09:14
  • Strictly speaking a viewer showing those changing in-document visualization by current standards is broken. Adobe seem to think it is necessary for backwards compatibility (probably their legal department want that) and, therefore, publish broken viewers. Removal may be attempted as described in [this answer using the generic approach](https://stackoverflow.com/a/56021333/1729265). Beware, though: Changes after signing may be indicated by a PDF viewer, e.g. like in the screenshots in [this answer](https://stackoverflow.com/a/37070234/1729265). – mkl May 27 '20 at 12:04
  • @mkl, Thanks for your ans, but I do not want to change entire appearance I just want to remove yellow question mark during view in my application , please let me know using which property in your suggested ans I can set AcroFields as true so that yellow question mark gets disappear. – Urmi_VV_Developer Jun 03 '20 at 13:26
  • Please make this a question in its own right. And please do provide a representative example PDF. And explain in which PDF viewers you currently get that yellow question mark (you mention *your application* which I obviously don't know). – mkl Jun 03 '20 at 15:22
  • @mkl, here is the link to newly posted question : https://stackoverflow.com/questions/62187593/remove-validity-unknown-sysmbol-after-signing-the-pdf-itextsharp-c-sharp – Urmi_VV_Developer Jun 04 '20 at 05:45