We are pleased to announce the new GrapeCity Documents v4.2 Maintenance Release 4.2.0.719/2.2.15 (GcPdfViewer). In this release, we make some new additions to our existing API to cater to our customer requests. Check out the new highlights below!
Further enhancements have been made to Digital Signatures support in GcPdf.
GcPdf now supports PAdES standard for signing PDF documents. In this release, we support the PAdES B-B and B-T levels. Two new static utility methods, 'CreatePAdES_B_B(..)', and 'CreatePAdES_B_T(..)' have been added to the SignatureProperties class.
Use these methods to create a SignatureProperties instance that can be used to sign a PDF with a respective PAdES level signature. Both methods can be passed a chain of certificates (the first certificate is used for signing).
The following code snippet shows how to use these methods:
GcPdfDocument doc = new GcPdfDocument();
doc.Load(fs);
X509Certificate2 cert = new X509Certificate2("User.pfx", "**");
SignatureProperties sp = SignatureProperties.CreatePAdES_B_B(cert);
sp.SignatureAppearance.Caption = "PAdES B-B";
sp.SignatureField = doc.AcroForm.Fields[0];
doc.Sign(sp, "signed_PAdES_B_B.pdf");
The following APIs have been added to apply a PAdES B-B and B-T levels:
You can now sign existing signatures with a .p12 extension certificate. See the following code for a demonstration:
using (FileStream fs = new FileStream(@"AdobePDFWithEmptySignatureField.pdf", FileMode.Open))
{
GcPdfDocument doc = new GcPdfDocument();
doc.Load(fs);
SignatureProperties sp = new SignatureProperties();
sp.SignatureBuilder = new Pkcs7SignatureBuilder()
{
CertificateChain = SecurityUtils.GetCertificateChain("1571753451.p12", "**"),
};
sp.SignatureField = doc.AcroForm.Fields[0];
doc.Sign(sp, "signed.pdf");
}
The new Pkcs7SignatureBuilder.CertificateChain object allows you to embed a full chain of certificates into the signature.
using (FileStream fs = new FileStream(@"AdobePDFWithEmptySignatureField.pdf", FileMode.Open))
{
GcPdfDocument doc = new GcPdfDocument();
doc.Load(fs);
SignatureProperties sp = new SignatureProperties();
sp.SignatureBuilder = new Pkcs7SignatureBuilder()
{
CertificateChain = SecurityUtils.GetCertificateChain("1571753451.p12", "**"),
};
sp.SignatureField = doc.AcroForm.Fields[0];
doc.Sign(sp, "signed.pdf");
}
We now support signing a PDF document using Azure KeyVault. This can be done using AzureSignatureGenerator class added for demo purposes. You can find full implementation in this demo.
When a PDF is signed, you can store the certificate in different locations, e.g., on a hardware 'token' etc. Some common interfaces allow working with such certificate sources.
These will now be supported in GcPdf. The Pkcs11SignatureGenerator class helps sign a PDF using a USB token and has been added for demo purposes. Please find the full implementation of the class in this demo.
In v4.2 release, we introduced the API to add layers (optional content) to PDF documents. In this release, we now add support showing/hiding layers in our JavaScript based GrapeCity Documents PDF Viewer (GcPdfViewer). The viewer provides viewer.addLayersPanel() method, to add layers panel to the viewer.
In addition, the viewer API adds new optionalContentConfig property that allows users to:
The following code snippets demonstrate how to use the new property:
// Use the addLayersPanel method to add Layers panel to the viewer UI:
viewer.addLayersPanel();
...
// Use the optionalContentConfig property to print information about the available layers to the console:
const config = await viewer.optionalContentConfig;
console.table(config.getGroups());
...
// Use the optionalContentConfig property to toggle layers visibility from code:
const config = await viewer.optionalContentConfig;
// Hide the optional content group (layer) with id "13R":
config.setVisibility("13R", false);
// Repaint visible pages:
viewer.repaint();
A few other methods have been added to the viewer:
Check more details below.
A new method has been added to the Paragraph class: RestartList(int? startNumberingValue = null). This method will restart the list numbering on the current paragraph. If the optional parameter is omitted, numbering on the current list will be restarted. Otherwise, a new list will be created.
Note that the current paragraph must belong to a numbered list. If not, an exception will be thrown.
The following code demonstrates how to restart the list at various levels:
GcWordDocument doc = new GcWordDocument();
var pars = doc.Body.Sections.First.GetRange().Paragraphs;
pars.Add("A numbered list with 3 levels:");
// A ListTemplate is used to make paragraphs part of a list:
var myListTemplate = doc.ListTemplates.Add(BuiltInListTemplateId.NumberDefault, "myListTemplate");
// Add a 3-level numbered nested list:
addItem("Top item 1", 0);
addItem("Top item 2", 0);
addItem("Top item 3", 0);
addItem("Nested item 1", 1);
addItem("Nested item 2", 1);
addItem("Double nested item 1", 2);
addItem("Double nested item 2", 2);
// Restart a list with default numbering:
addItem("Double nested item 3 - restart at 'i'", 2).RestartList();
addItem("Double nested item 4", 2);
addItem("Double nested item 5", 2);
addItem("Nested item 3", 1);
addItem("Nested item 4", 1);
addItem("Nested item 5", 1);
addItem("Nested item 6", 1);
// Restart a letter-numbered ("a, b, c,...") list at letter 'c':
addItem("Nested item 7 - restart at 'c'", 1).RestartList(3);
addItem("Nested item 8", 1);
addItem("Nested item 9", 1);
addItem("Top item 4", 0);
addItem("Top item 5", 0);