1

Here is the code that create signature appearance before signing document.

PdfStamper stamper = PdfStamper.CreateSignature(reader, os, '\0');
// Creating the appearance
PdfSignatureAppearance appearance = stamper.SignatureAppearance;
appearance.Reason = "Lorem apsum";
appearance.Contact = "";
appearance.Location = "";
appearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.DESCRIPTION;
appearance.CertificationLevel = PdfSignatureAppearance.NOT_CERTIFIED;
appearance.SetVisibleSignature(new iTextSharp.text.Rectangle(10, 10, 149, 69), reader.NumberOfPages, "Page1_Loc_5");
//Creating the appearance

Here Contact property is empty that I want to fill with Name of the signer

I am getting name of the signer from userX509Certificate.

string responseXML = System.IO.File.ReadAllText(Server.MapPath("~/ResponseSignatureXML.txt"));
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(responseXML);
XmlElement EsignResp = xmlDoc.DocumentElement;
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("UserX509Certificate");
Byte[] Certificate = Encoding.UTF8.GetBytes(nodeList[0].FirstChild.InnerText);

X509Certificate cert = new X509Certificate(Certificate);
string CertificateIssuedTo = cert.GetName();

@Note: this signer name is not available while preparing the signature appearance.

After preparing file with appearance. calculate the hash of that file(i.e src file) and call external service, in response I am getting xmlsiganture, which I used to place the signature on my document.

How do I append/change signature visualization in my src file before placing signature?

code that place the signature on document.(signature response with pkcs7 signature)

XmlNodeList nodeList = xmlDoc.GetElementsByTagName("Signatures");
string signature = nodeList[0].FirstChild.InnerText;
using (PdfReader reader = new PdfReader(src))
{
    using (FileStream os = new FileStream(dest, FileMode.Create))
    {
        byte[] encodedSignature = Convert.FromBase64String(signature);
        IExternalSignatureContainer external = new MyExternalSignatureContainer(encodedSignature);
        MakeSignature.SignDeferred(reader, "Page1_Loc_5", os, external);
    }
}

Here Digitally signed by is showing blank instead of signer name.

enter image description here

Here is screenshot from documentation which I am referring for digital signature. C# Code How it is showing Digitaly signed by Bruno Spiceman as signer name enter image description here

Mannan Bahelim
  • 1,289
  • 1
  • 11
  • 31
  • 1
    You say *"this signer name is not available while preparing the signature appearance"*; thus, it **obviously** cannot be in the generated signature appearance, can it? So why do you ask *"Why signature visualization not showing signer name in pdf when signed by Itextsharp library?"* [This answer](https://stackoverflow.com/a/56021333/1729265) can help you manipulate the PDF after signing to change the signature appearance. – mkl May 07 '19 at 12:41
  • Is there any default Appearance class in itextsharp? – Mannan Bahelim May 07 '19 at 12:45
  • 1
    What do you mean by "default Appearance class itextsharp"? – mkl May 07 '19 at 12:46
  • Thanks @mkl, let me try with comment answer code https://stackoverflow.com/a/56021333/5326667 – Mannan Bahelim May 07 '19 at 12:51
  • @mkl Thanks a lot, Its working. Actually problem here is vendor who provide this service follow this bad architecture.there no additional service to provide signer name before signing document. Thanks Again for this awesome code. – Mannan Bahelim May 07 '19 at 14:04
  • 1
    Ok, as that answer resolved your issue, I closed your question as duplicate thereof. – mkl May 07 '19 at 15:39

0 Answers0