原創(chuàng)|產(chǎn)品更新|編輯:李顯亮|2020-12-28 09:59:27.057|閱讀 243 次
概述:Spire.PDF for .NET更新至v6.12.20,該版本支持通過(guò)外部服務(wù)進(jìn)行數(shù)字簽名并且支持設(shè)置PDF包中文件的字段并對(duì)文件進(jìn)行排序。此外還增強(qiáng)了PDF轉(zhuǎn)換到PDF/A 和PDF/A -3b的功能,以及修復(fù)了在查找文本中出現(xiàn)的問(wèn)題,歡迎下載體驗(yàn)。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
Spire.PDF for .NET是一款獨(dú)立 PDF 控件,用于 .NET 程序中創(chuàng)建、編輯和操作 PDF 文檔。使用 Spire.PDF 類(lèi)庫(kù),開(kāi)發(fā)人員可以新建一個(gè) PDF 文檔或者對(duì)現(xiàn)有的 PDF 文檔進(jìn)行處理,且無(wú)需安裝 Adobe Acrobat。操作簡(jiǎn)單,易上手,國(guó)產(chǎn)廠商提供優(yōu)質(zhì)便捷的技術(shù)支持。
近日,Spire.PDF for .NET也迎來(lái)了2020年12月更新發(fā)布!該版本支持通過(guò)外部服務(wù)進(jìn)行數(shù)字簽名并且支持設(shè)置PDF包中文件的字段并對(duì)文件進(jìn)行排序。此外還增強(qiáng)了PDF轉(zhuǎn)換到PDF/A 和PDF/A -3b的功能,以及修復(fù)了在查找文本中出現(xiàn)的問(wèn)題,具體更新內(nèi)容如下:
新功能
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 signaturepublic 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; } }
string[] files = Directory.GetFiles(@"files"); string inputFile = @"input.pdf"; string outputFile = @"result.pdf"; using (PdfDocument doc = new PdfDocument(inputFile)) { //添加字段 doc.Collection.AddCustomField("No", "序號(hào)", Spire.Pdf.Collections.CustomFieldType.NumberField); doc.Collection.AddFileRelatedField("FileName", "文件名稱(chēng)", Spire.Pdf.Collections.FileRelatedFieldType.FileName); doc.Collection.AddFileRelatedField("Desc", "文件描述", Spire.Pdf.Collections.FileRelatedFieldType.Desc); doc.Collection.AddFileRelatedField("CreateDate", "創(chuàng)建時(shí)間", Spire.Pdf.Collections.FileRelatedFieldType.CreationDate); doc.Collection.AddFileRelatedField("ModDate", "修改時(shí)間", Spire.Pdf.Collections.FileRelatedFieldType.ModDate); doc.Collection.AddFileRelatedField("FileSize", "文件大小", Spire.Pdf.Collections.FileRelatedFieldType.Size); doc.Collection.AddCustomField("FileType", "文件類(lèi)型", Spire.Pdf.Collections.CustomFieldType.TextField); doc.Collection.AddCustomField("FileDate", "自定義時(shí)間", Spire.Pdf.Collections.CustomFieldType.DateField); //根據(jù)字段對(duì)附件排序 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; //設(shè)置字段值 foreach (PdfAttachment att in doc.Collection.AssociatedFiles) { att.SetFieldValue("No", n); att.Description = n + "文件描述"; att.SetFieldValue("FileDate", DateTime.Today); att.SetFieldValue("FileType", n + "文件"); n++; } doc.SaveToFile(outputFile, FileFormat.PDF); doc.Dispose(); }
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);
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修復(fù)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn