News & Releases
|
|

Spire.PDF 6.12.20 supports digitally signing PDF through external services
We are happy to announce the release of Spire.PDF 6.12.20. This version supports digitally signing PDF through external services as well as setting the file fields for PDF Portfolios and sorting the files. Meanwhile, it also enhances the conversions from PDF to PDF/A and PDF/A -3b and fixes the issue occurred in the process of finding texts. More details are given below.
Here is a list of changes made in this release
| Category | ID | Description |
| New Feature | SPIREPDF-2609 SPIREPDF-2804 SPIREPDF-3351 SPIREPDF-3527 SPIREPDF-3775 |
Supports digitally signing the PDF through external services.
void Sign()
{
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(inputPath);
//Load the certificate
X509Certificate2 cert = new X509Certificate2(certPath, passwd);
CustomPKCS7SignatureFormatter customPKCS7SignatureFormatter = new CustomPKCS7SignatureFormatter(cert);
PdfSignature signature = new PdfSignature(doc, doc.Pages[0], customPKCS7SignatureFormatter, "signature0");
signature.Bounds = new RectangleF(new PointF(90, 550), new SizeF(270, 90));
//Set the dispay mode of graphics, if not set any, the default one will be applied
signature.GraphicsMode = GraphicMode.SignDetail;
signature.NameLabel = "Signer:";
signature.Name = "gary";
signature.ContactInfoLabel = "ContactInfo:";
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "Chengdu";
signature.ReasonLabel = "Reason: ";
signature.Reason = "The certificate of this document";
signature.DistinguishedNameLabel = "DN: ";
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
signature.SignDetailsFont = new PdfFont(PdfFontFamily.TimesRoman, 10f);
signature.SignNameFont = new PdfFont(PdfFontFamily.Courier, 15);
signature.SignImageLayout = SignImageLayout.None;
//Save pdf file.
doc.SaveToFile(outputPath, Spire.Pdf.FileFormat.PDF);
}
class CustomPKCS7SignatureFormatter : IPdfSignatureFormatter
{
///
/// If encapsulate is true, a copy of the message will be included in the signature.
///
private bool m_encapsulate = true;
///
/// The signing certificate.
///
private X509Certificate2 m_certificate = null;
public Dictionary m_parameters = new Dictionary();
///
/// Parameters for the encoding of the signature.
/// 1.Key:Filter,String
/// Required
/// The name of the preferred signature handler to use when validating this signature.
/// 2.SubFilter,String
/// Required
/// A name that describes the encoding of the signature value.
/// PDF 1.6 defines the following values for public-key cryptographic signatures: adbe.x509.rsa_sha1, adbe.pkcs7.detached, and adbe.pkcs7.sha1
/// 3.Cert,X509Certificate2
/// Required when SubFilter is adbe.x509.rsa_sha1
///
public Dictionary Parameters
{
get
{ return m_parameters; }
}
///
/// Construct a new instance.
///
/// The signing certificate.
///
/// If encapsulate is true, a copy of the message will be included in the signature.
///
public CustomPKCS7SignatureFormatter(X509Certificate2 certificate)
{
if (null == certificate)
{ throw new ArgumentNullException("certificate"); }
m_certificate = certificate;
Parameters.Add("Filter", "Adobe.PPKMS");
Parameters.Add("SubFilter", m_encapsulate ? "adbe.pkcs7.sha1" : "adbe.pkcs7.detached");
}
///
/// Sign.
///
/// The data that contains signature content.
/// The signature
public byte[] Sign(byte[] content)
{
CmsSigner cmsSigner = new CmsSigner(m_certificate);
SHA1 sha1 = SHA1.Create();
SignedCms signedCms = new SignedCms(new ContentInfo(m_encapsulate ? sha1.ComputeHash(content) : content), !m_encapsulate);
signedCms.ComputeSignature(cmsSigner, true);
byte[] result = signedCms.Encode();
return result;
}
}
|
| New Feature | SPIREPDF-3724 | Support setting the file fields for PDF Portfolios and sorting the files.
string[] files = Directory.GetFiles(@"files");
string inputFile = @"input.pdf";
string outputFile = @"output.pdf";
using (PdfDocument doc = new PdfDocument(inputFile))
{
//Add the custom field
doc.Collection.AddCustomField("No", "No", Spire.Pdf.Collections.CustomFieldType.NumberField);
doc.Collection.AddFileRelatedField("FileName", "FileName", Spire.Pdf.Collections.FileRelatedFieldType.FileName);
doc.Collection.AddFileRelatedField("Desc", "Desc", Spire.Pdf.Collections.FileRelatedFieldType.Desc);
doc.Collection.AddFileRelatedField("CreateDate", "CreateDate", Spire.Pdf.Collections.FileRelatedFieldType.CreationDate);
doc.Collection.AddFileRelatedField("ModDate", "ModDate", Spire.Pdf.Collections.FileRelatedFieldType.ModDate);
doc.Collection.AddFileRelatedField("FileSize", "FileSize", Spire.Pdf.Collections.FileRelatedFieldType.Size);
doc.Collection.AddCustomField("FileType", "FileType", Spire.Pdf.Collections.CustomFieldType.TextField);
doc.Collection.AddCustomField("FileDate", "FileDate", Spire.Pdf.Collections.CustomFieldType.DateField);
//Sort the file
doc.Collection.Sort(new string[] { "No", "fileName", "Desc", "CreateDate", "ModDate", "FileSize", "FileType", "FileDate" }, new bool[] { false, true, true, true, true, true, true, true });
for (int i = 0; i < files.Length; i++)
{
PdfAttachment attachment = new PdfAttachment(files[i]);
doc.Collection.AddAttachment(attachment);
}
int n = 1;
//Set the field value
foreach (PdfAttachment att in doc.Collection.AssociatedFiles)
{
att.SetFieldValue("No", n);
att.Description = n + "description";
att.SetFieldValue("FileDate", DateTime.Today);
att.SetFieldValue("FileType", n + "file");
n++;
}
doc.SaveToFile(outputFile, FileFormat.PDF);
doc.Dispose();
}
|
| New Feature | SPIREPDF-3786 | Supports setting the attachment relationship when adding attachments.
PdfDocument doc = new PdfDocument(); doc.LoadFromFile(inputPath); PdfAttachment attachment = new PdfAttachment(attachmentPath); doc.Attachments.Add(attachment,doc,Spire.Pdf.General.PdfAttachmentRelationship.Alternative); doc.SaveToFile(outputPath); |
| New Feature | SPIREPDF-3867 | Supports finding text in a specific area.
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(inputFile, FileFormat.PDF);
RectangleF rctg = new RectangleF(0, 0, 200, 100);
PdfTextFindCollection findCollection = pdf.Pages[0].FindText(rctg, "DEPOSIT", TextFindParameter.WholeWord);
PdfTextFindCollection findCollectionOut = pdf.Pages[0].FindText(rctg, "agreement", TextFindParameter.WholeWord);
foreach (PdfTextFind find in findCollection.Finds)
{ find.ApplyHighLight(Color.Green); }
foreach (PdfTextFind findOut in findCollectionOut.Finds)
{ findOut.ApplyHighLight(Color.Yellow); }
pdf.SaveToFile(outputFile, FileFormat.PDF);
|
| Bug | SPIREPDF-3706 | Fixes the issue that the generated file did not conform to the standard of PDF/A-3B after converting PDF with attachments to PDF/A-3B. |
| Bug | SPIREPDF-3719 | Fixes the issue that the generated files did not conform to the standard of PDF/A after converting PDF with actions to PDF/A. |
| Bug | SPIREPDF-3802 | Fixes the issue that the application hung when getting the bookmarks. |
| Bug | SPIREPDF-3825 | Adjusts the initialization method of PdfTrueTypeFont class for .NET Standard APIs |
| Bug | SPIREPDF-3837 | Fixes the issue that the annotations couldn't be removed. |
| Bug | SPIREPDF-3852 | Fixes the issue that the character spacing were incorrect after adding subscripts and subscripts. |
| Bug | SPIREPDF-3856 | Fixes the issue that the application threw the error "NullReferenceException" when finding the text. |
| Bug | SPIREPDF-3870 | Fixes the issue that not all matches were found when finding text. |
Click the link to download Spire.PDF 6.12.20:
More information of Spire.PDF new release or hotfix: