VintaSoft Imaging .NET SDK 15.2: Документация для .NET разработчика
Vintasoft.Imaging.Pdf Namespace / PdfPageDigitalSignatureHelper Class / SignDocument Methods / SignDocument(String,String,Int32,PdfAConverter) Method
Синтаксис Example Требования Смотрите также
В этом разделе
SignDocument(String,String,Int32,PdfAConverter) Метод (PdfPageDigitalSignatureHelper)
В этом разделе
Добавляет цифровую подпись на PDF страницу и сохраняет документ в формате PDF/A.
Синтаксис
'Declaration

Public Overloads Sub SignDocument( _
ByVal inputFilename
Имя входного PDF файла.
As System.String, _
ByVal pageIndex
Индекс PDF страницы, на которую необходимо добавить цифровую подпись.
As System.String, _
ByVal outputFilename
Имя выходного PDF файла.
As System.Int32, _
ByVal pdfAConverter
Конвертер документов PDF/A.
As Vintasoft.Imaging.Pdf.Processing.PdfA.PdfAConverter _
)
public void SignDocument(
System.String inputFilename,
System.String pageIndex,
System.Int32 outputFilename,
Vintasoft.Imaging.Pdf.Processing.PdfA.PdfAConverter pdfAConverter
)

Parameters

inputFilename
Имя входного PDF файла.
pageIndex
Индекс PDF страницы, на которую необходимо добавить цифровую подпись.
outputFilename
Имя выходного PDF файла.
pdfAConverter
Конвертер документов PDF/A.
Пример

Вот пример, который показывает, как подписать PDF/A документ, используя указанную цифровую подпись:


Imports System.Drawing
Imports System.Security.Cryptography.X509Certificates
Imports Vintasoft.Imaging.Pdf
Imports Vintasoft.Imaging.Pdf.Processing
Imports Vintasoft.Imaging.Pdf.Processing.PdfA

''' <summary>
''' Adds digital signature to a PDF page and converts PDF document to a PDF/A format.
''' </summary>
Public Class PdfPageDigitalSignatureHelper_PdfA
    Public Shared Sub Run()
        ' get the X509 certificate from .pfx-file
        Using certificate As New X509Certificate2("TestCertificate.pfx", "test")
            ' create a helper that alows to add digital signature to a PDF document
            Dim digitalSignatureHelper As New PdfPageDigitalSignatureHelper(certificate, New RectangleF(10, 10, 250, 75))

            ' set the reason for signing
            digitalSignatureHelper.SigningReason = "Test signing"

            ' set text for signature appearance
            digitalSignatureHelper.SignatureText = String.Format("Digitally signed by" & vbLf & "{0}", digitalSignatureHelper.SignerName)

            ' create PDF/A-1b converter
            Dim pdfAConverter As PdfAConverter = DirectCast(PdfDocumentConverter.Create(PdfDocumentConformance.PdfA_1b), PdfAConverter)
            pdfAConverter.DefaultCmykIccProfileFilename = "DefaultCMYK.icc"
            pdfAConverter.DefaultRgbIccProfileFilename = "DefaultRGB.icc"

            ' 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, pdfAConverter)
        End Using
    End Sub
End Class


using System.Drawing;
using System.Security.Cryptography.X509Certificates;
using Vintasoft.Imaging.Pdf;
using Vintasoft.Imaging.Pdf.Processing;
using Vintasoft.Imaging.Pdf.Processing.PdfA;

/// <summary>
/// Adds digital signature to a PDF page and converts PDF document to a PDF/A format.
/// </summary>
public class PdfPageDigitalSignatureHelper_PdfA
{
    public static void Run()
    {
        // get the X509 certificate from .pfx-file
        using (X509Certificate2 certificate = new X509Certificate2("TestCertificate.pfx", "test"))
        {
            // create a helper that alows to add digital signature to a PDF document
            PdfPageDigitalSignatureHelper digitalSignatureHelper =
                new PdfPageDigitalSignatureHelper(certificate, new RectangleF(10, 10, 250, 75));

            // set the reason for signing
            digitalSignatureHelper.SigningReason = "Test signing";

            // set text for signature appearance
            digitalSignatureHelper.SignatureText = string.Format("Digitally signed by\n{0}", digitalSignatureHelper.SignerName);

            // create PDF/A-1b converter
            PdfAConverter pdfAConverter = (PdfAConverter)PdfDocumentConverter.Create(PdfDocumentConformance.PdfA_1b);
            pdfAConverter.DefaultCmykIccProfileFilename = "DefaultCMYK.icc";
            pdfAConverter.DefaultRgbIccProfileFilename = "DefaultRGB.icc";

            // 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, pdfAConverter);
        }
    }
}

Требования

Целевые платформы: .NET 11; .NET 10; .NET 9; .NET 8; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

Смотрите также