static void PAdES_B_B() { // If using Professional version, put your serial key below. ComponentInfo.SetLicense("FREE-LIMITED-KEY"); using (var document = PdfDocument.Load("Reading.pdf")) { // Add a visible signature field to the first page of the PDF document. var signatureField = document.Form.Fields.AddSignature(document.Pages[0], 300, 500, 250, 50); // Get a digital ID from PKCS#12/PFX file. var digitalId = new PdfDigitalId("GemBoxECDsa521.pfx", "GemBoxPassword"); // Create a PDF signer that will create PAdES B-B level signature. var signer = new PdfSigner(digitalId); // PdfSigner should create CAdES-equivalent signature. signer.SignatureFormat = PdfSignatureFormat.CAdES; // Adobe Acrobat Reader currently doesn't download certificate chain // so we will also embed certificate of intermediate Certificate Authority in the signature. // (see https://community.adobe.com/t5/acrobat/signature-validation-using-aia-extension-not-enabled-by-default/td-p/10729647) signer.ValidationInfo = new PdfSignatureValidationInfo(new PdfCertificate[] { new PdfCertificate("GemBoxECDsa.crt") }, null, null); // Make sure that all properties specified on PdfSigner are according to PAdES B-B level. signer.SignatureLevel = PdfSignatureLevel.PAdES_B_B; // Initiate signing of a PDF file with the specified signer. signatureField.Sign(signer); // Finish signing of a PDF file. document.Save("PAdES B-B.pdf"); } }
static void SimpleSignature() { // If using Professional version, put your serial key below. ComponentInfo.SetLicense("FREE-LIMITED-KEY"); using (var document = PdfDocument.Load("Reading.pdf")) { // Add an invisible signature field to the PDF document. var signatureField = document.Form.Fields.AddSignature(); // Get a digital ID from PKCS#12/PFX file. var digitalId = new PdfDigitalId("GemBoxRSA1024.pfx", "GemBoxPassword"); // Create a PDF signer that will create the digital signature. var signer = new PdfSigner(digitalId); // Adobe Acrobat Reader currently doesn't download certificate chain // so we will also embed certificate of intermediate Certificate Authority in the signature. // (see https://community.adobe.com/t5/acrobat/signature-validation-using-aia-extension-not-enabled-by-default/td-p/10729647) signer.ValidationInfo = new PdfSignatureValidationInfo(new PdfCertificate[] { new PdfCertificate("GemBoxRSA.crt") }, null, null); // Initiate signing of a PDF file with the specified signer. signatureField.Sign(signer); // Finish signing of a PDF file. document.Save("Digital Signature.pdf"); } }
static void PAdES_B_LTA() { // If using Professional version, put your serial key below. ComponentInfo.SetLicense("FREE-LIMITED-KEY"); using (var document = PdfDocument.Load("Reading.pdf")) { // Add a visible signature field to the first page of the PDF document. var signatureField = document.Form.Fields.AddSignature(document.Pages[0], 300, 500, 250, 50); // Get a digital ID from PKCS#12/PFX file. var digitalId = new PdfDigitalId("GemBoxECDsa521.pfx", "GemBoxPassword"); // Create a PDF signer that will create PAdES B-LTA level signature. var signer = new PdfSigner(digitalId); // PdfSigner should create CAdES-equivalent signature. signer.SignatureFormat = PdfSignatureFormat.CAdES; // PdfSigner will embed a timestamp created by freeTSA.org Time Stamp Authority in the signature. signer.Timestamper = new PdfTimestamper("https://freetsa.org/tsr"); // Make sure that all properties specified on PdfSigner are according to PAdES B-LTA level. signer.SignatureLevel = PdfSignatureLevel.PAdES_B_LTA; // Initiate signing of a PDF file with the specified signer. signatureField.Sign(signer); // Finish signing of a PDF file. document.Save("PAdES B-LTA.pdf"); // Download validation-related information for the signature and the signature's timestamp and embed it in the PDF file. // This will make the signature "LTV enabled". document.SecurityStore.AddValidationInfo(signatureField.Value); // Add an invisible signature field to the PDF document that will hold the document timestamp. var timestampField = document.Form.Fields.AddSignature(); // Initiate timestamping of a PDF file with the specified timestamper. timestampField.Timestamp(signer.Timestamper); // Save any changes done to the PDF file that were done since the last time Save was called and // finish timestamping of a PDF file. document.Save(); } }
static void VisibleSignature() { // If using Professional version, put your serial key below. ComponentInfo.SetLicense("FREE-LIMITED-KEY"); using (var document = PdfDocument.Load("Reading.pdf")) { // Add a visible signature field to the first page of the PDF document. var signatureField = document.Form.Fields.AddSignature(document.Pages[0], 300, 500, 250, 50); // Retrieve signature appearance settings to customize it. var signatureAppearance = signatureField.Appearance; // Show 'Reason' label and value. signatureAppearance.Reason = "Legal agreement"; // Show 'Location' label and value. signatureAppearance.Location = "New York, USA"; // Do not show 'Date' label nor value. signatureAppearance.DateFormat = string.Empty; // Get a digital ID from PKCS#12/PFX file. var digitalId = new PdfDigitalId("GemBoxRSA1024.pfx", "GemBoxPassword"); // Create a PDF signer that will create the digital signature. var signer = new PdfSigner(digitalId); // Adobe Acrobat Reader currently doesn't download certificate chain // so we will also embed certificate of intermediate Certificate Authority in the signature. // (see https://community.adobe.com/t5/acrobat/signature-validation-using-aia-extension-not-enabled-by-default/td-p/10729647) signer.ValidationInfo = new PdfSignatureValidationInfo(new PdfCertificate[] { new PdfCertificate("GemBoxRSA.crt") }, null, null); // Initiate signing of a PDF file with the specified signer. signatureField.Sign(signer); // Finish signing of a PDF file. document.Save("Visible Digital Signature.pdf"); } }
static void PAdES_B_LTA() { // If using Professional version, put your serial key below. ComponentInfo.SetLicense("FREE-LIMITED-KEY"); var document = DocumentModel.Load("Reading.docx"); // Create visual representation of digital signature. var signature = new Picture(document, "GemBoxSignature.png"); // Position signature image at the end of the document. var lastSection = document.Sections[document.Sections.Count - 1]; lastSection.Blocks.Add(new Paragraph(document, signature)); // If using Professional version, put your serial key below. GemBox.Pdf.ComponentInfo.SetLicense("FREE-LIMITED-KEY"); // Get a digital ID from PKCS#12/PFX file. var digitalId = new PdfDigitalId("GemBoxECDsa521.pfx", "GemBoxPassword"); // Create a PDF signer that will create PAdES B-LTA level signature. var signer = new PdfSigner(digitalId); // PdfSigner should create CAdES-equivalent signature. signer.SignatureFormat = PdfSignatureFormat.CAdES; // PdfSigner will embed a timestamp created by freeTSA.org Time Stamp Authority in the signature. signer.Timestamper = new PdfTimestamper("https://freetsa.org/tsr"); // Make sure that all properties specified on PdfSigner are according to PAdES B-LTA level. signer.SignatureLevel = PdfSignatureLevel.PAdES_B_LTA; // Inject PdfSigner from GemBox.Pdf into // PdfDigitalSignatureSaveOptions from GemBox.Document. var signatureOptions = PdfDigitalSignatureSaveOptions.FromSigner( () => signer.SignatureFormat.ToString(), () => signer.EstimatedSignatureContentsLength, signer.ComputeSignature); signatureOptions.Signature = signature; var options = new PdfSaveOptions() { DigitalSignature = signatureOptions }; document.Save("PAdES B-LTA.pdf", options); using (var pdfDocument = GemBox.Pdf.PdfDocument.Load("PAdES B-LTA.pdf")) { var signatureField = (PdfSignatureField)pdfDocument.Form.Fields[0]; // Download validation-related information for the signature and the signature's timestamp and embed it in the PDF file. // This will make the signature "LTV enabled". pdfDocument.SecurityStore.AddValidationInfo(signatureField.Value); // Add an invisible signature field to the PDF document that will hold the document timestamp. var timestampField = pdfDocument.Form.Fields.AddSignature(); // Initiate timestamping of a PDF file with the specified timestamper. timestampField.Timestamp(signer.Timestamper); // Save any changes done to the PDF file that were done since the last time Save was called and // finish timestamping of a PDF file. pdfDocument.Save(); } }