没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
原创|产品更新|编辑:李显亮|2020-12-28 09:59:27.057|阅读 252 次
概述:Spire.PDF for .NET更新至v6.12.20,该版本支持通过外部服务进行数字签名并且支持设置PDF包中文件的字段并对文件进行排序。此外还增强了PDF转换到PDF/A 和PDF/A -3b的功能,以及修复了在查找文本中出现的问题,欢迎下载体验。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
Spire.PDF for .NET是一款独立 PDF 控件,用于 .NET 程序中创建、编辑和操作 PDF 文档。使用 Spire.PDF 类库,开发人员可以新建一个 PDF 文档或者对现有的 PDF 文档进行处理,且无需安装 Adobe Acrobat。操作简单,易上手,国产厂商提供优质便捷的技术支持。
近日,Spire.PDF for .NET也迎来了2020年12月更新发布!该版本支持通过外部服务进行数字签名并且支持设置PDF包中文件的字段并对文件进行排序。此外还增强了PDF转换到PDF/A 和PDF/A -3b的功能,以及修复了在查找文本中出现的问题,具体更新内容如下:
新功能
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", "序号", 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修复
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn




DevExpress WinForms控件v25.1日前已经全新发布,新版本的Ribbon、PDF Viewer(查看器)等组件功能全新升级等,欢迎下载最新版体验!
界面控件DevExpress WinForms v25.2将于今年年末左右更新,新版本将继续升级富文本编辑器控件功能等,欢迎关注我们及时获取最新消息~
PHP IDE——PhpStorm 发布了重大更新v2025.2,此版本官宣支持PHPUnit 12 、Junie 编码智能体重大升级等,欢迎下载最新版体验!
DevExpress WinForms控件v25.1日前已经全新发布,新版本全新数据编辑器、AI聊天控件功能增强等,欢迎下载最新版体验!
相关产品
Spire.PDF for .NET是独立的PDF控件,用于.NET程序中创建、编辑和操作PDF文档
最新文章 MORE
半岛外围网上直营相关的文章 MORE
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@ke049m.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
半岛外围网上直营