翻譯|使用教程|編輯:李顯亮|2020-04-21 09:34:29.307|閱讀 466 次
概述:在本系列教程中,將為開(kāi)發(fā)者帶來(lái)Aspose.PDF for .NET的一系列使用教程,例如進(jìn)行文檔間的轉(zhuǎn)換,如何標(biāo)記PDF文件,如何使用表單和圖表等等。本文將介紹如何提取圖像和簽名信息。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
Aspose.PDF for .NET是一種高PDF處理和解析API,用于在跨平臺(tái)應(yīng)用程序中執(zhí)行文檔管理和操作任務(wù)。API可以輕松用于生成、修改、轉(zhuǎn)換、渲染、保護(hù)和打印PDF文檔,而無(wú)需使用Adobe Acrobat。此外,API還提供PDF壓縮選項(xiàng),表格創(chuàng)建和操作,圖形和圖像功能,廣泛的超鏈接功能,印章和水印任務(wù),擴(kuò)展的安全控制和自定義字體處理。
在接下來(lái)的系列教程中,將為開(kāi)發(fā)者帶來(lái)Aspose.PDF for .NET的一系列使用教程,例如進(jìn)行文檔間的轉(zhuǎn)換,如何標(biāo)記PDF文件,如何使用表單和圖表等等。本文將介紹如何提取圖像和簽名信息。
>>Aspose.PDF for .NET更新至最新版v20.4,歡迎下載體驗(yàn)。
.NET的Aspose.PDF支持使用SignatureField類(lèi)對(duì)PDF文件進(jìn)行數(shù)字簽名的功能,并且在簽名文檔時(shí),還可以為設(shè)置圖像SignatureAppearance。現(xiàn)在,該API還提供了提取簽名信息以及與簽名字段關(guān)聯(lián)的圖像的功能。
為了提取簽名信息,將ExtractImage(..)方法引入了SignatureField該類(lèi)。請(qǐng)查看以下代碼片段,該代碼片段演示了從SignatureField對(duì)象提取圖像的步驟:
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures(); string input = dataDir+ @"ExtractingImage.pdf"; using (Document pdfDocument = new Document(input)) { foreach (Field field in pdfDocument.Form) { SignatureField sf = field as SignatureField; if (sf != null) { string outFile = dataDir+ @"output_out.jpg"; using (Stream imageStream = sf.ExtractImage()) { if (imageStream != null) { using (System.Drawing.Image image = Bitmap.FromStream(imageStream)) { image.Save(outFile, System.Drawing.Imaging.ImageFormat.Jpeg); } } } } } }
有時(shí)可能只需要替換PDF文件中已經(jīng)存在的簽名字段的圖像。為了實(shí)現(xiàn)此要求,首先,我們需要在PDF文件中搜索表單字段,標(biāo)識(shí)簽名字段,獲取簽名字段的尺寸(矩形尺寸),然后在相同尺寸上標(biāo)記圖像。
用于.NET的Aspose.PDF支持使用SignatureField該類(lèi)對(duì)PDF文件進(jìn)行數(shù)字簽名的功能。目前,還可以確定證書(shū)的有效性,但不能提取整個(gè)證書(shū)。可以提取的信息是公鑰,指紋,發(fā)行者等。
為了提取簽名信息,將ExtractCertificate(..)方法引入了SignatureField該類(lèi)。請(qǐng)查看以下代碼片段,該代碼片段演示了從SignatureField對(duì)象提取證書(shū)的步驟:
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures(); string input = dataDir + "ExtractSignatureInfo.pdf"; using (Document pdfDocument = new Document(input)) { foreach (Field field in pdfDocument.Form) { SignatureField sf = field as SignatureField; if (sf != null) { Stream cerStream = sf.ExtractCertificate(); if (cerStream != null) { using (cerStream) { byte[] bytes = new byte[cerStream.Length]; using (FileStream fs = new FileStream(dataDir + @"input.cer", FileMode.CreateNew)) { cerStream.Read(bytes, 0, bytes.Length); fs.Write(bytes, 0, bytes.Length); } } } } } }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@ke049m.cn