您的位置:首页 > 编程语言 > C#

在C#代码中提取PDF中的注释文本

2015-11-13 17:36 489 查看
//这里要引用using iTextSharp.text;using iTextSharp.text.pdf;
PdfReader myPdfReader = new PdfReader(@"C:\Users\Administrator\Desktop\加快QTP运行速度的建议.pdf");
int a = myPdfReader.NumberOfPages;
PdfDictionary pageDict = myPdfReader.GetPageN(1);
PdfArray annotArray = pageDict.GetAsArray(PdfName.ANNOTS);
if (annotArray == null) return;
for (int i = 0; i < annotArray.Size; ++i)
{
PdfDictionary curAnnot = annotArray.GetAsDict(i);
string sSubType = curAnnot.Get(PdfName.SUBTYPE).ToString();
if (sSubType == "/FreeText")
{
PdfString pdfString = curAnnot.GetAsString(PdfName.CONTENTS);
if (pdfString != null)
{
string value = pdfString.ToUnicodeString();
System.Windows.Forms.MessageBox.Show(value);
}
}
//PdfDictionary annot = (PdfDictionary)PdfReader.GetPdfObject(annotArray[i]);
//PdfString content = (PdfString)PdfReader.GetPdfObject(curAnnot.Get(PdfName.CONTENTS));
//if (content != null)
//{
//    System.Windows.Forms.MessageBox.Show(content.ToUnicodeString());
//}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: