日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

itextsharp 获取文本_使用itextsharp从签名图像中获取Layer2文本(签名描述)

發布時間:2024/1/8 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 itextsharp 获取文本_使用itextsharp从签名图像中获取Layer2文本(签名描述) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

雖然Bruno以包含"第2層"的PDF開頭解決了這個問題,但請允許我先說明使用這些"簽名層"在PDF簽名外觀是不 PDF規范,規范實際上根本不知道這些層!因此,如果您嘗試解析特定圖層,則可能找不到這樣的圖層"或者更糟糕的是,找到一個看起來像那個包含錯誤數據的圖層(一個名為n2的XObject)的東西。

盡管如此,無論您是從第2層查找文本還是從簽名外觀中查找文本,都可以使用iTextSharp文本提取功能。我使用Bruno的代碼作為檢索n2圖層的基礎。

public static void ExtractSignatureTextFromFile(FileInfo file)

{

try

{

Console.Out.Write("File: {0}\n", file);

using (var pdfReader = new PdfReader(file.FullName))

{

AcroFields fields = pdfReader.AcroFields;

foreach (string name in fields.GetSignatureNames())

{

Console.Out.Write(" Signature: {0}\n", name);

iTextSharp.text.pdf.AcroFields.Item item = fields.GetFieldItem(name);

PdfDictionary widget = item.GetWidget(0);

PdfDictionary ap = widget.GetAsDict(PdfName.AP);

if (ap == null)

continue;

PdfStream normal = ap.GetAsStream(PdfName.N);

if (normal == null)

continue;

Console.Out.Write(" Content of normal appearance: {0}\n", extractText(normal));

PdfDictionary resources = normal.GetAsDict(PdfName.RESOURCES);

if (resources == null)

continue;

PdfDictionary xobject = resources.GetAsDict(PdfName.XOBJECT);

if (xobject == null)

continue;

PdfStream frm = xobject.GetAsStream(PdfName.FRM);

if (frm == null)

continue;

PdfDictionary res = frm.GetAsDict(PdfName.RESOURCES);

if (res == null)

continue;

PdfDictionary xobj = res.GetAsDict(PdfName.XOBJECT);

if (xobj == null)

continue;

PRStream n2 = (PRStream) xobj.GetAsStream(PdfName.N2);

if (n2 == null)

continue;

Console.Out.Write(" Content of normal appearance, layer 2: {0}\n", extractText(n2));

}

}

}

catch (Exception ex)

{

Console.Error.Write("Error... " + ex.StackTrace);

}

}

public static String extractText(PdfStream xObject)

{

PdfDictionary resources = xObject.GetAsDict(PdfName.RESOURCES);

ITextExtractionStrategy strategy = new LocationTextExtractionStrategy();

PdfContentStreamProcessor processor = new PdfContentStreamProcessor(strategy);

processor.ProcessContent(ContentByteUtils.GetContentBytesFromContentObject(xObject), resources);

return strategy.GetResultantText();

}

File: ...\signature_n2.pdf

Signature: Signature1

Content of normal appearance: This document was signed by Bruno

Specimen.

Content of normal appearance, layer 2: This document was signed by Bruno

Specimen.

由于此示例使用OP期望的第2層,因此它已包含相關文本。

總結

以上是生活随笔為你收集整理的itextsharp 获取文本_使用itextsharp从签名图像中获取Layer2文本(签名描述)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。