XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to HTML5 Viewer & Editor PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Edit Digital Signatures
  |  
Home ›› XDoc.PDF ›› C# PDF: Edit PDF Digital Signature

C#.NET PDF SDK - Add Digital Signatures to PDF in C#.NET


C# Solutions for Improving the Security of Your PDF File by Adding Digital Signatures in Visual C#.NET Class




Best .NET framework PDF SDK library for PDF signature manipulation in Visual C# .NET WinForms and ASP.NET WebForm project


Provide free PDF signing application component to add signature to PDF file in C#.NET project


Able to use online C# source code to create a signature for PDF document in Visual Studio .NET program


Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint


Able to digitally sign a PDF file without adobe reader installed


Add a signature or an empty signature field in any PDF file page


Ability to insert signature in PDF form


Detect and search signature field in PDF document


Insert PDF signature certificate to sign PDF file


Verify the validity of PDF signature


Remove signature from PDF document








C# add digital signature to PDF document


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




        #region add digital signature to PDF document
        internal static void addDigitalSignature()
        {
            String inputFilePath = @"...";
            String outputFilePath = @"...";
            String imagePath = @"...";
            String certSubjectName = @"...";
            String fieldID = @"...";

            X509Cert cert = PDFDigitalSignatureHandler.MakeCert(StoreName.My, StoreLocation.CurrentUser, certSubjectName);

            // Set cert properties.
            cert.Location = "CHINA SHANGHAI";
            cert.Reason = "Reason";
            cert.APMode = APMode.Text; // APMode.Text | APMode.Image.
            cert.Image = new Bitmap(imagePath);

            if (PDFDigitalSignatureHandler.Sign(inputFilePath, outputFilePath, cert, fieldID) == 0)
            {
                Console.WriteLine("[SUCCESS]");
            }
            else
            {
                Console.WriteLine("[FAILED]");
            }
        }
        #endregion




C# search unsigned signature field in the PDF document





String inputFilePath = @"...";
List<SignatureField> vals = PDFDigitalSignatureHandler.SearchUnsignedFields(inputFilePath);
if (vals == null || vals.Count == 0)
{
    Console.WriteLine("No Signature Field");
}
else
{
    Console.WriteLine("Signature Fields");

    for (int i = 0; i < vals.Count; i++)
    {
        Console.WriteLine(i + ": " + vals[i].ID + " (Pg " + vals[i].PageIndex + ")");
    }
}




C# prepare a certification which used to sign a document





StoreName storeName = StoreName.My;
StoreLocation storeLocation = StoreLocation.CurrentUser;
String subjectName = "";

List<String> allSubjects = PDFDigitalSignatureHandler.GetAllSubjectNames(storeName, storeLocation, true);
foreach (String str in allSubjects)
{
    Console.WriteLine("Make certification by name: " + str);
    X509Cert cert = PDFDigitalSignatureHandler.MakeCert(storeName, storeLocation, str);

//	
}




C# add an empty signature field to pdf document





String inputFilePath = @"...";
String outputFilePath = @"...";

PDFSignature signature = new PDFSignature(new RectangleF(10F, 10F, 250F, 150F));
if (PDFDigitalSignatureHandler.CreateSignatureField(inputFilePath, outputFilePath, signature, 0) == 0)
{
    Console.WriteLine("[SUCCESS]");
}
else
{
    Console.WriteLine("[FAILED]");
}




C# sign a PDF document





String inputFilePath = @"...";
String outputFilePath = @"...";
String imagePath = @"...";
String certSubjectName = @"...";
String fieldID = @"...";

X509Cert cert = PDFDigitalSignatureHandler.MakeCert(StoreName.My, StoreLocation.CurrentUser, certSubjectName);
//  set cert properties
cert.Location = "CHINA SHANGHAI";
cert.Reason = "Reason";
cert.APMode = APMode.Text;      //  APMode.Text | APMode.Image
cert.Image = new Bitmap(imagePath);

if (PDFDigitalSignatureHandler.Sign(inputFilePath, outputFilePath, cert, fieldID) == 0)
{
    Console.WriteLine("[SUCCESS]");
}
else
{
    Console.WriteLine("[FAILED]");
}




.NET Class Namespace Required



Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;