VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
In This Topic
    PDF: How to add invisible digital signature to a PDF document?
    In This Topic
    Here is C#/VB.NET code that demonstrates how to add invisible digital signature to a PDF document using PdfPageDigitalSignatureHelper class:
    using System.Security.Cryptography.X509Certificates;
    using Vintasoft.Imaging.Pdf;
    
    /// <summary>
    /// Adds invisible digital signature to a PDF page.
    /// </summary>
    public class PdfPageDigitalSignatureHelper_InvisibleAppearance
    {
        public static void Run()
        {
            // get the X509 certificate from .pfx-file
            using (X509Certificate2 certificate = new X509Certificate2("TestCertificate.pfx", "test"))
            {
                // create a helper that allows to add digital signature to a PDF document
                PdfPageDigitalSignatureHelper digitalSignatureHelper = new PdfPageDigitalSignatureHelper(certificate);
    
                // set the reason for signing
                digitalSignatureHelper.SigningReason = "Approve document";
    
                // add digital signature to the first PDF page, sign PDF document and save PDF document to the output file
                digitalSignatureHelper.SignDocument("TestDocumentToSign.pdf", "TestDocumentToSign-signed.pdf", 0);
            }
        }
    }
    
    Imports System.Security.Cryptography.X509Certificates
    Imports Vintasoft.Imaging.Pdf
    
    ''' <summary>
    ''' Adds invisible digital signature to a PDF page.
    ''' </summary>
    Public Class PdfPageDigitalSignatureHelper_InvisibleAppearance
        Public Shared Sub Run()
            ' get the X509 certificate from .pfx-file
            Using certificate As New X509Certificate2("TestCertificate.pfx", "test")
                ' create a helper that allows to add digital signature to a PDF document
                Dim digitalSignatureHelper As New PdfPageDigitalSignatureHelper(certificate)
    
                ' set the reason for signing
                digitalSignatureHelper.SigningReason = "Approve document"
    
                ' add digital signature to the first PDF page, sign PDF document and save PDF document to the output file
                digitalSignatureHelper.SignDocument("TestDocumentToSign.pdf", "TestDocumentToSign-signed.pdf", 0)
            End Using
        End Sub
    End Class
    
    


    Here is C#/VB.NET code that demonstrates how to add invisible digital signature to a PDF document using PdfPage.AddInvisibleDigitalSignature method:
    using System.Security.Cryptography.X509Certificates;
    using Vintasoft.Imaging.Pdf;
    using Vintasoft.Imaging.Pdf.Tree;
    
    /// <summary>
    /// Adds invisible digital signature to a PDF page.
    /// </summary>
    public class PdfPage_AddInvisibleDigitalSignature
    {
        public static void Run()
        {
            // get the X509 certificate from .pfx-file
            using (X509Certificate2 certificate = new X509Certificate2("TestCertificate.pfx", "test"))
            {
                // open PDF document
                using (PdfDocument pdfDocument = new PdfDocument("TestDocumentToSign.pdf"))
                {
                    // get the first PDF page
                    PdfPage pdfPage = pdfDocument.Pages[0];
    
                    // add an invisible digital signature to the PDF page
                    pdfPage.AddInvisibleDigitalSignature(
                        certificate, "Signature", "Approve document", false);
    
                    // sign PDF document and save PDF document to the output file
                    pdfDocument.SaveChanges("TestDocumentToSign-signed.pdf");
                }
            }
        }
    }
    
    
    Imports System.Security.Cryptography.X509Certificates
    Imports Vintasoft.Imaging.Pdf
    Imports Vintasoft.Imaging.Pdf.Tree
    
    ''' <summary>
    ''' Adds invisible digital signature to a PDF page.
    ''' </summary>
    Public Class PdfPage_AddInvisibleDigitalSignature
        Public Shared Sub Run()
            ' get the X509 certificate from .pfx-file
            Using certificate As New X509Certificate2("TestCertificate.pfx", "test")
                ' open PDF document
                Using pdfDocument As New PdfDocument("TestDocumentToSign.pdf")
                    ' get the first PDF page
                    Dim pdfPage As PdfPage = pdfDocument.Pages(0)
    
                    ' add an invisible digital signature to the PDF page
                    pdfPage.AddInvisibleDigitalSignature(certificate, "Signature", "Approve document", False)
    
                    ' sign PDF document and save PDF document to the output file
                    pdfDocument.SaveChanges("TestDocumentToSign-signed.pdf")
                End Using
            End Using
        End Sub
    End Class