当前位置: 首页 > 编程语言 > C#

c#itextsharp如何获取数字签名图片分享

时间:2023-04-10 19:35:13 C#

c#itextsharp如何获取数字签名图片是否可以使用itextsharp使用c#代码获取pdf文件中的任何数字签名图像?PdfReaderpdf=newPdfReader("location.pdf");AcroFieldsacroFields=pdf.AcroFields;列表名称=acroFields.GetSignatureNames();foreach(varnameinnames){PdfDictionarydict=acroFields.GetSignatureDictionary(name);简单的线条,我可以得到签名字典,但是从这个对象中我无法得到图像的内容。有人可以帮忙吗?我回答了我自己的问题......如果它对其他人有用,我会这样做。我找到了一个Java类来做我想做的事,我用C#翻译了它。类XyzmoSignatureDataExtractor{私有PdfReader阅读器;publicXyzmoSignatureDataExtractor(PdfReaderreader){this.reader=reader;}publicPdfImageObjectextractImage(StringsignatureName){MyImageRenderListenerlistener=newMyImageRenderListener();PdfDictionarysigFieldDic=reader.AcroFields.GetFieldItem(signatureName).GetMerged(0);PdfDictionaryappearancesDic=sigFieldDic.GetAsDict(PdfName.AP);PdfStreamnormalAppearance=appearancesDic.GetAsStream(PdfName.N);PdfDictionaryresourcesDic=normalAppearance.GetAsDict(PdfName.RESOURCES);PdfContentStreamProcessor处理器=newPdfContentStreamProcessor(listener);processor.ProcessContent(ContentByteUtils.GetContentBytesFromContentObject(normalAppearance),resourcesDic);返回listener.image;}classMyImageRenderListener:IRenderListener{publicvoidBeginTextBlock(){}publicvoidEndTextBlock(){}publicvoidRenderImage(ImageRenderInforenderInfo){try{image=renderInfo.GetImage();}catch(Exceptione){thrownewException("获取图片失败",e);}}publicvoidRenderText(TextRenderInforenderInfo){}publicPdfImageObjectimage=null;}}要使用这个类和保存图片,我只需要这样做:以上是C#学习教程:c#itextsharp如何获取数字签名图片分享的全部内容。如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注——PdfReaderreader=newPdfReader("location.pdf");XyzmoSignatureDataExtractor提取器=newXyzmoSignatureDataExtractor(reader);AcroFieldsacroFields=reader.AcroFields;foreach(acroFields.GetSignatureNames()中的字符串名称){PdfImageObjectimage=extractor.extractImage(var_image=image.GetDrawingImage();stringfile_name="sig."+image.GetFileType();_image.Save(file_name);}本文收集自网络,不代表立场,如涉及侵权,请点击右边联系管理员删除,如需转载请注明出处: