SignPAdESBB.vb
''
'' This code is part of Document Solutions for PDF .NET demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System
Imports System.IO
Imports System.Drawing
Imports System.Text
Imports System.Collections.Generic
Imports System.Security.Cryptography
Imports System.Security.Cryptography.X509Certificates
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Pdf.Security
Imports GrapeCity.Documents.Pdf.AcroForms
Imports GrapeCity.Documents.Text

'' This sample shows how to sign an existing PDF file containing
'' an empty signature field with a signature that complies with
'' PAdES (PDF Advanced Electronic Signatures) B-B level standard.
Public Class SignPAdESBB
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Using s = File.OpenRead(Path.Combine("Resources", "PDFs", "SignPAdESBB.pdf"))
            doc.Load(s)

            Dim pfxPath = Path.Combine("Resources", "Misc", "DsPdfTest.pfx")
            Dim cert = New X509Certificate2(pfxPath, "qq")
            Dim sp = SignatureProperties.CreatePAdES_B_B(cert)
            sp.SignatureAppearance.Caption = "PAdES B-B"
            sp.SignatureField = doc.AcroForm.Fields(0)
            doc.Sign(sp, stream)
        End Using

        '' Done.
        Return doc.Pages.Count
    End Function
End Class