【发布时间】:2016-05-15 21:55:11
【问题描述】:
我有一个问题,无法从 PDF 文件中提取突出显示的文本。 str 变量始终为空。任何人都可以帮助我吗?
我的代码:
private static string GetPdfHighlighText(string file, int page) {
string nv = "";
PdfReader reader = new PdfReader(file);
for (int x = 1; x < reader.NumberOfPages; x++)
{
PdfDictionary pageDict = reader.GetPageN(x);
PdfArray annots = pageDict.GetAsArray(PdfName.ANNOTS);
if (annots != null)
{
for (int i = 1; i <= annots.Size; ++i)
{
PdfDictionary annotationDic = (PdfDictionary)PdfReader.GetPdfObject(annots[i]);
PdfName subType = (PdfName)annotationDic.Get(PdfName.SUBTYPE);
if (subType.Equals(PdfName.HIGHLIGHT))
{
PdfString str = annots.GetAsString(i);
nv = nv + str;
}
}
}
}
return nv; }
我正在使用 ITextSharp 库。 PFLibrary 是 iTextSharp.text.pdf 命名空间。
我想从 pdf 中扫描所有页面并提取所有突出显示的文本, 它是 245 页,但我会每页放置过滤器。我可以识别突出显示的注释,但没有返回突出显示文本的字符串
【问题讨论】:
标签: c# pdf itextsharp