SignPAdESBT.cs
C# VB
//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//using System.IO;using System.Security.Cryptography.X509Certificates;
using GrapeCity.Documents.Pdf;

namespace DsPdfWeb.Demos{ // 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-T level standard. public class SignPAdESBT { public int CreatePDF(Stream stream) { var doc = new GcPdfDocument(); using var s = File.OpenRead(Path.Combine("Resources", "PDFs", "SignPAdESBT.pdf")); doc.Load(s);
var pfxPath = Path.Combine("Resources", "Misc", "DsPdfTest.pfx"); var cert = new X509Certificate2(pfxPath, "qq"); var sp = SignatureProperties.CreatePAdES_B_T(new TimeStamp("https://freetsa.org/tsr"), cert); sp.SignatureAppearance.Caption = "PAdES B-T"; sp.SignatureField = doc.AcroForm.Fields[0]; doc.Sign(sp, stream);
// Done. return doc.Pages.Count; } }}