Home > Software engineering >  I want add digital signature in my dynamic pdf with using itext sharp and in signature insert acrofi
I want add digital signature in my dynamic pdf with using itext sharp and in signature insert acrofi

Time:04-26

I was trying to insert textfield in digtal signature with using itextsharp but not able to insert that text in esignature.

My code please check Also I want verify that signature still not able to do this code any suggestion would be appriciate..

https://imgur.com/SF11oH1

public void Sign(string SigReason, string SigContact, string SigLocation, bool visible)
{
    string password = @"123";
    PdfReader reader = new PdfReader(this.inputPDF,new System.Text.ASCIIEncoding().GetBytes(password));
    //Activate MultiSignatures
    PdfStamper st = PdfStamper.CreateSignature(reader, new FileStream(this.outputPDF, FileMode.Create, FileAccess.Write), '\0', null, true);
    //To disable Multi signatures uncomment this line : every new signature will invalidate older ones !
    //PdfStamper st = PdfStamper.CreateSignature(reader, new FileStream(this.outputPDF, FileMode.Create, FileAccess.Write), '\0'); 
    //string pdfTemplate = Server.MapPath("~/Data/PADForm.pdf");
    //string newFile = Server.MapPath("~/Data/newFile.pdf");

    //signPdfFile(sourceDocument, destinationPath, stream, "123", "testing", "testing");
    //PdfReader pdfReader = new PdfReader(pdfTemplate, new System.Text.ASCIIEncoding().GetBytes(password));
    //PdfStamper pdfStamper = new PdfStamper(reader, new FileStream(this.outputPDF, FileMode.Create));
    string imageURL = @"C:\Users\amitrs\Desktop\FSI SS\204-25.png";
    iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
   // Resize image depend upon your need
    jpg.ScaleToFit(140f, 120f);
    //Give space before image

    jpg.SpacingBefore = 10f;

    //Give some space after the image

    jpg.SpacingAfter = 1f;

    jpg.Alignment = Element.ALIGN_LEFT;
    AcroFields pdfFormFields = st.AcroFields;
    pdfFormFields.SetField("DigitalSignature", "Amit");
    pdfFormFields.SetField("Signature", "Amit Saini");
    st.MoreInfo = this.metadata.getMetaData();
    st.XmpMetadata = this.metadata.getStreamedMetaData();
    PdfSignatureAppearance sap = st.SignatureAppearance;
   
    
    sap.SetCrypto(this.myCert.Akp, this.myCert.Chain, null, PdfSignatureAppearance.VERISIGN_SIGNED);
    sap.Reason = SigReason;
    sap.Contact = SigContact;
    sap.Location = SigLocation;            
    if (visible)
        sap.SetVisibleSignature(new iTextSharp.text.Rectangle(100, 100, 250, 300), 1, null);
    
    st.Close();
}

CodePudding user response:

iTextSharp signature appearance object have 2 property, you have to set property.

PdfSignatureAppearance sap = st.SignatureAppearance;
sap.Layer2Text = "XYZ";

Hope this helps

  • Related