none
I want to add digital signature in a PDF file using asp.net and C# RRS feed

  • General discussion

  • How to implement or add a digital signature in a pdf file using Asp.net and microsoft C#.

    Can anyone explain?.

    Like I'm working on a Gov. project and its related generate chalan from a report dropdown section to send the user. Chalan will be in PDF format and digitally signed and approved by any signatory authority. 

    So, please help me out to do this. 

    Tuesday, June 11, 2019 11:25 AM

All replies

  • .NET does not support working with PDF files directly. For PDF you'll need to use a third party library like iTextSharp ore equivalent. For questions on how to use those libraries to do what you ask you'll need to post in their forums. This forum is for C#-specific questions only.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, June 11, 2019 2:11 PM
    Moderator
  • Hi Krishna,

    Thank you for posting here.

    Since this thread is related to asp.net, I suggest that you could post in the following forum.

    https://forums.asp.net/

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Jack


    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.

    Wednesday, June 12, 2019 2:26 AM
  • Hi, you may take a look at the following code which is capble of adding a digital signater to a certain page of a PDF document. This solution relies on a .NET PDF component called Spire.PDF. 

    //load a pdf document
    PdfDocument doc = new PdfDocument();
    doc.LoadFromFile(@"C:\Users\Administrator\Desktop\test.pdf");
    
    //load the certificate
    PdfCertificate cert = new PdfCertificate(@"C:\Users\Administrator\Desktop\gary.pfx", "e-iceblue");
    
    //initialize a PdfSignature instance
    PdfSignature signature = new PdfSignature(doc, doc.Pages[0], cert, "Signature1");
    
    //set the signature location
    signature.Bounds = new RectangleF(new PointF(200, 200), new SizeF(200, 90));
    
    //set the image of signature
    signature.SignImageSource = PdfImage.FromFile(@"C:\Users\Administrator\Desktop\signImage.png");
    
    //set the content of signature
    signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;
    signature.NameLabel = "Signer:";
    signature.Name = "Gary";
    signature.ContactInfoLabel = "ContactInfo:";
    signature.ContactInfo = signature.Certificate.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, true);
    signature.DistinguishedNameLabel = "DN: ";
    signature.DistinguishedName = signature.Certificate.IssuerName.Name;
    signature.LocationInfoLabel = "Location:";
    signature.LocationInfo = "Chengdu";
    signature.ReasonLabel = "Reason: ";
    signature.Reason = "Le document est certifie";
    signature.DateLabel = "Date:";
    signature.Date = DateTime.Now;
    signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
    signature.Certificated = true;
    
    //set fonts
    signature.SignDetailsFont = new PdfFont(PdfFontFamily.TimesRoman, 10f);
    signature.SignNameFont = new PdfFont(PdfFontFamily.Courier, 15);
    
    //set the sign image layout mode
    signature.SignImageLayout = SignImageLayout.None;
    
    //save the file
    doc.SaveToFile("signature.pdf");
    Thursday, June 13, 2019 7:37 AM
  • You may try using GroupDocs.Signature for .NET (https://products.groupdocs.com/signature/net) to add digital signatures to the PDF documents. You can sign a single as well as multiple pages of the source document. 

    SignatureConfig config = new SignatureConfig();
    config.StoragePath = "D:\\storage\\";
    config.OutputPath = "D:\\output\\";
    config.ImagesPath = ""D:\\images\\"";
    config.CertificatesPath = "D:\\certificates\\";
    
    // instantiate the signature handler
    var handler = new SignatureHandler(config);
    // setup digital signature options
    var signOptions = new PdfSignDigitalOptions("sample.pfx", "sign.png");
    // image position
    signOptions.Left = 100;
    signOptions.Top = 100;
    signOptions.Width = 100;
    signOptions.Height = 100;
    signOptions.Visible = true;
    signOptions.SignAllPages = true;
    signOptions.HorizontalAlignment = Domain.HorizontalAlignment.Center;
    signOptions.VerticalAlignment = Domain.VerticalAlignment.Top;
    signOptions.DocumentPageNumber = 1;
    // add signature
    string signedDocumentPath = handler.Sign<string>("sample.pdf", signOptions, new SaveOptions { OutputType = OutputType.String });




    • Edited by usman.aziz Saturday, June 15, 2019 5:00 PM
    Saturday, June 15, 2019 4:58 PM