how to add digital signature in pdf using asp net c# without mvc. I want full code as I am new to asp.net

Tarang Rohit 1 Reputation point
2022-01-12T06:54:45.393+00:00

Hello,

I want to upload pdf file. After uploading file, I want to sign that pdf file using my Digital Certificate which is in Pen Drive format attached to my Computer.

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | ASP.NET | Other
Developer technologies | C#
{count} votes

2 answers

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,096 Reputation points
    2022-01-14T07:23:52.353+00:00

    Hi @Tarang Rohit ,
    You could add a digital signature to a pdf document using SelectPdf Library for .NET.

    protected void BtnCreatePdf_Click(object sender, EventArgs e)  
            {  
                // create a new pdf document  
                PdfDocument doc = new PdfDocument();  
      
                // add a new page to the document  
                PdfPage page = doc.AddPage();  
      
                // get image path   
                // the image will be used to display the digital signature over it  
                string imgFile = Server.MapPath("~/files/logo.png");  
      
                // get certificate path  
                string certFile = Server.MapPath("~/files/selectpdf.pfx");  
      
                // define a rendering result object  
                PdfRenderingResult result;  
      
                // create image element from file path   
                PdfImageElement img = new PdfImageElement(0, 0, imgFile);  
                result = page.Add(img);  
      
                // get the #PKCS12 certificate from file  
                PdfDigitalCertificatesCollection certificates =   
                    PdfDigitalCertificatesStore.GetCertificates(certFile, "selectpdf");  
                PdfDigitalCertificate certificate = certificates[0];  
      
                // create the digital signature object  
                PdfDigitalSignatureElement signature =   
                    new PdfDigitalSignatureElement(result.PdfPageLastRectangle, certificate);  
                signature.Reason = "SelectPdf";  
                signature.ContactInfo = "SelectPdf";  
                signature.Location = "SelectPdf";  
                page.Add(signature);  
      
                // save pdf document  
                doc.Save(Response, false, "Sample.pdf");  
      
                // close pdf document  
                doc.Close();  
            }  
    

    Best regards,
    Yijing Sun


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.