彩票走势图

12月更新!PDF文档开发API-Spire.PDF新版发布!支持更多文档格式转换

原创|产品更新|编辑:李显亮|2020-12-31 10:05:23.740|阅读 383 次

概述:Spire.PDF的.NET和java版均已迎来12月的更新,本文是更新详情。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

Spire.PDF是专业的PDF API,适用于创建,编写,编辑,处理和读取PDF文件,且无需安装Adobe Acrobat。11月常规更新已发布,下面是具体的更新情况。

Spire.PDF for .NET更新至v6.12.20,该版本支持通过外部服务进行数字签名并且支持设置PDF包中文件的字段并对文件进行排序。此外还增强了PDF转换到PDF/A 和PDF/A -3b的功能,以及修复了在查找文本中出现的问题。

下载Spire.PDF for .NET最新版

新功能

  • 支持通过外部服务进行数字签名。
    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;
                }
            }
  • 支持设置PDF包中文件的字段并对文件进行排序。
    string[] files = Directory.GetFiles(@"files");
    string inputFile = @"input.pdf";
    string outputFile = @"result.pdf";
    using (PdfDocument doc = new PdfDocument(inputFile))
    {
        //添加字段
        doc.Collection.AddCustomField("No", "序号", Spire.Pdf.Collections.CustomFieldType.NumberField);
        doc.Collection.AddFileRelatedField("FileName", "文件名称", Spire.Pdf.Collections.FileRelatedFieldType.FileName);
        doc.Collection.AddFileRelatedField("Desc", "文件描述", Spire.Pdf.Collections.FileRelatedFieldType.Desc);
        doc.Collection.AddFileRelatedField("CreateDate", "创建时间", Spire.Pdf.Collections.FileRelatedFieldType.CreationDate);
        doc.Collection.AddFileRelatedField("ModDate", "修改时间", Spire.Pdf.Collections.FileRelatedFieldType.ModDate);
        doc.Collection.AddFileRelatedField("FileSize", "文件大小", Spire.Pdf.Collections.FileRelatedFieldType.Size);
        doc.Collection.AddCustomField("FileType", "文件类型", Spire.Pdf.Collections.CustomFieldType.TextField);
        doc.Collection.AddCustomField("FileDate", "自定义时间", Spire.Pdf.Collections.CustomFieldType.DateField);
    
        //根据字段对附件排序
        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; //设置字段值 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修复

Spire.PDF for Java更新至v3.12.6,该版本支持了转换PDF到TIFF,改善了doc.getPages().get(0).isBlank()方法逻辑,实现了提取PDF文本按照段落断行以及读取和写入XMP元数据的功能。此外,该版本还增强了转换PDF到Image/Excel/Word的功能。

下载Spire.PDF for Java最新版

新功能

  • 支持了转换PDF到TIFF。
    PdfDocument pdf=new PdfDocument();
    pdf.loadFromFile("C:/Test.pdf");
    pdf.saveToTiff("C:/1.tiff");
    pdf.saveToTiff("C:/2.tiff",1,2,TiffCompressionTypes.DEFAULT);
  • 改善了doc.getPages().get(0).isBlank()方法逻辑。
  • 实现了提取PDF文本按照段落断行的功能。
    PdfDocument doc = new PdfDocument();
    // 加载PDF文档
    doc.loadFromFile(InputPath);
    doc.getConvertOptions().setKeepParagraph(true);
    File file = new File(OutputPath);
    file.createNewFile();
    FileWriter fw = new FileWriter(file, true);
    BufferedWriter bw = new BufferedWriter(fw);
    StringBuilder builder = new StringBuilder();
    PdfPageBase pageBase;
    for (int i = 0; i < doc.getPages().getCount(); i++) { pageBase = doc.getPages().get(i); builder.append(pageBase.extractText(false) + "\r\n"); } bw.write(builder.toString()); bw.flush(); bw.close(); fw.close(); doc.close();
  • 实现了读取和写入XMP元数据。
    PdfDocument pdf=new PdfDocument();
    pdf.loadFromFile("C:/test.pdf");
    //Get Xmp meta data
    String lcXml = pdf.getXmpMetaData().getXmlString();
    PdfDocument newDoc=new PdfDocument();
    newDoc.getPages().add();
    //Write Xmp meta data to PDF
    newDoc.getXmpMetaData().load(lcXml);
    newDoc.saveToFile("C:/new.pdf");

Bug修复


【慧都17周年庆】Aspose、E-iceblue、FastReport、Stimulsoft等文档/报表图表类开发工具85折起,如有需要可直接。

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP