none
Create Signature field in PDF RRS feed

  • Question

  • Hi ,

      I want to develop create signature field in PDF document , and draw signature on pdf by using c#  

    Thursday, January 17, 2019 1:43 PM

All replies

  • .NET does not support PDFs out of the box. You'll need to look into a third party library like iTextSharp. Please post questions related to using third party products in their forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, January 17, 2019 2:37 PM
    Moderator
  • You can consider using spire.pdf library to do it. Hope the below code can help you.

    Create signature field:

    using System.Drawing;
    using Spire.Pdf;
    using Spire.Pdf.Fields;
    using Spire.Pdf.Graphics;
    
    namespace AddSignatureField
    {
        class Program
        {
            static void Main(string[] args)
            {
                PdfDocument pdfdoc = new PdfDocument();
                pdfdoc.LoadFromFile("Input.pdf");
    
                PdfPageBase page = pdfdoc.Pages[0];
    
                PdfSignatureField signaturefield = new PdfSignatureField(page, "Signature");
    
                signaturefield.BorderWidth = 1.0f;
                signaturefield.BorderStyle = PdfBorderStyle.Solid;
                signaturefield.BorderColor = new PdfRGBColor(System.Drawing.Color.Black);
                signaturefield.HighlightMode = PdfHighlightMode.Outline;
                signaturefield.Bounds = new RectangleF(100, 100, 100, 100);
    
                pdfdoc.Form.Fields.Add(signaturefield);
    
                pdfdoc.SaveToFile("AddSignField.pdf", FileFormat.PDF);
            }
        }
    }

    Fill signature field:

    PdfDocument pdf = new PdfDocument();
    pdf.LoadFromFile("AddSignField.pdf");
    
    PdfCertificate cert = new PdfCertificate(@"C:\Users\Test1\Desktop\michael.pfx", "pwd");
    
    //Get the list of filed collection, and determine if there is a signature filed
    PdfFormWidget widgets = pdf.Form as PdfFormWidget;
    
    for (int i = 0; i < widgets.FieldsWidget.List.Count; i++)
    {
        PdfFieldWidget widget = widgets.FieldsWidget.List[i] as PdfFieldWidget;
        if (widget is PdfSignatureFieldWidget)
        {
            //Sign in the existing signature field 
            string sgn = widget.Name;
            PdfSignatureFieldWidget SignWidge = widget as PdfSignatureFieldWidget;
            PdfSignature signature = new PdfSignature(pdf, pdf.Pages[0], cert, sgn, SignWidge);
            signature.DistinguishedName = "DN:";
            signature.NameLabel = "Digital Signed By:";
            signature.Name = "Ankush";
            signature.ContactInfo = "Lisa";
            signature.Date = DateTime.Now;
            signature.Certificated = false;
            signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
            signature.SignDetailsFont = new PdfTrueTypeFont(new Font("Times New Roman", 12f), true);
            //PdfImage pdfImage = PdfImage.FromFile(@"C:\Users\Test1\Desktop\resul111t.png");
            //signature.SignImageSource = pdfImage;
            //signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;
            //signature.SignImageLayout = SignImageLayout.None;
        }
    }
    
    pdf.SaveToFile("Signed.pdf");

     
    • Edited by Michael Brrr Friday, January 18, 2019 2:51 AM
    • Proposed as answer by tommytwotrain Friday, January 18, 2019 8:33 AM
    • Unproposed as answer by tommytwotrain Friday, January 18, 2019 8:33 AM
    Friday, January 18, 2019 2:48 AM
  • Hi Navasshereef1,

    Thank you for posting here.

    For your question, please refer to the examples in the link below about how to create signature field in PDF via iText.

    https://itextpdf.com/en/search?query=signature

    Best Regards,

    Wendy

    Note: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Friday, February 1, 2019 7:39 AM
    Friday, January 18, 2019 6:52 AM
    Moderator