SignDocument(String,String,Int32,PdfAConverter) Method (PdfPageDigitalSignatureHelper)
In This Topic
Adds digital signature to the PDF page and saves document as a PDF/A document.
Syntax
'Declaration
Public Overloads Sub SignDocument( _
ByVal As System.String, _
ByVal As System.String, _
ByVal As System.Int32, _
ByVal As Vintasoft.Imaging.Pdf.Processing.PdfA.PdfAConverter _
)
public void SignDocument(
System.String ,
System.String ,
System.Int32 ,
Vintasoft.Imaging.Pdf.Processing.PdfA.PdfAConverter
)
public: void SignDocument(
System.String ,
System.String ,
System.Int32 ,
Vintasoft.Imaging.Pdf.Processing.PdfA.PdfAConverter*
)
public:
void SignDocument(
System.String ,
System.String ,
System.Int32 ,
Vintasoft.Imaging.Pdf.Processing.PdfA.PdfAConverter^
)
Parameters
- inputFilename
- The name of input PDF file.
- pageIndex
- The zero-based index of PDF page, where digital signature must be added.
- outputFilename
- The name of output PDF file.
- pdfAConverter
- The PDF/A document converter.
Example
Here is an example that shows how to sign a PDF/A document using the specified digital signature:
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
''' <summary>
''' Signs a PDF/A document using specified PFX file.
''' </summary>
''' <param name="inputFilename">The name of input PDF file.</param>
''' <param name="outputFilename">The name of output PDF file.</param>
''' <param name="pfxFileName">The name of PFX file.</param>
''' <param name="pfxFilePassword">The password for PDF file.</param>
''' <param name="pdfAConformance">PDF/A conformance.</param>
Public Shared Sub SignPdfDocument(inputFilename As String, outputFilename As String, pfxFileName As String, pfxFilePassword As String, pdfAConformance As PdfDocumentConformance)
Using certificate As New X509Certificate2(pfxFileName, pfxFileName)
' 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)
Dim pdfAConverter As PdfAConverter = Nothing
' if PDF document should be converted to a PDF/A format
If pdfAConformance <> PdfDocumentConformance.Undefined Then
' create PDF/A converter
pdfAConverter = DirectCast(PdfDocumentConverter.Create(pdfAConformance), PdfAConverter)
pdfAConverter.DefaultCmykIccProfileFilename = "DefaultCMYK.icc"
pdfAConverter.DefaultRgbIccProfileFilename = "DefaultRGB.icc"
End If
' add digital signature to the first PDF page, sign PDF document and save PDF document to the output file
digitalSignatureHelper.SignDocument(inputFilename, outputFilename, 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
{
/// <summary>
/// Signs a PDF/A document using specified PFX file.
/// </summary>
/// <param name="inputFilename">The name of input PDF file.</param>
/// <param name="outputFilename">The name of output PDF file.</param>
/// <param name="pfxFileName">The name of PFX file.</param>
/// <param name="pfxFilePassword">The password for PDF file.</param>
/// <param name="pdfAConformance">PDF/A conformance.</param>
public static void SignPdfDocument(
string inputFilename,
string outputFilename,
string pfxFileName,
string pfxFilePassword,
PdfDocumentConformance pdfAConformance)
{
using (X509Certificate2 certificate = new X509Certificate2(pfxFileName, pfxFileName))
{
// 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);
PdfAConverter pdfAConverter = null;
// if PDF document should be converted to a PDF/A format
if (pdfAConformance != PdfDocumentConformance.Undefined)
{
// create PDF/A converter
pdfAConverter = (PdfAConverter)PdfDocumentConverter.Create(pdfAConformance);
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(inputFilename, outputFilename, 0, pdfAConverter);
}
}
}
Requirements
Target Platforms: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
See Also