// 完毕:
using System;
using System.IO;
using System.Drawing;
using System.Text;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Pdf.Security;
using GrapeCity.Documents.Pdf.AcroForms;
using GrapeCity.Documents.Text;
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-B level standard.
public class SignPAdESBB
{
public int CreatePDF(Stream stream)
{
var doc = new GcPdfDocument();
using var s = File.OpenRead(Path.Combine("Resources", "PDFs", "SignPAdESBB.pdf"));
doc.Load(s);
var pfxPath = Path.Combine("Resources", "Misc", "DsPdfTest.pfx");
var cert = new X509Certificate2(pfxPath, "qq");
var sp = SignatureProperties.CreatePAdES_B_B(cert);
sp.SignatureAppearance.Caption = "PAdES B-B";
sp.SignatureField = doc.AcroForm.Fields[0];
doc.Sign(sp, stream);
// Done.
return doc.Pages.Count;
}
}
}