C# 尝试阅读标注,如何从iTextSharp中的PdfDictionary获取/IT的值?

C# 尝试阅读标注,如何从iTextSharp中的PdfDictionary获取/IT的值?,c#,pdf,itextsharp,C#,Pdf,Itextsharp,我想阅读PDF中的标注文本框。我使用iTextSharp遍历所有注释,如下所示: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using iTextSharp.text; using iTextSharp.text.pdf; using System.IO; namespace PDFAnnotationRe

我想阅读PDF中的标注文本框。我使用iTextSharp遍历所有注释,如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;

namespace PDFAnnotationReader
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder text = new StringBuilder();
            string fileName = @"C:\Users\J123\Desktop\xyz.pdf";
            PdfReader pdfReader = new PdfReader(fileName);
            PdfDictionary pageDict = pdfReader.GetPageN(1);
            PdfArray annotArray = pageDict.GetAsArray(PdfName.ANNOTS);
            for (int i=0;i<annotArray.Size;i++)
            {
                PdfDictionary curAnnot = annotArray.GetAsDict(i);
            }
        }
    }
因此,我认为我应该检查每个注释,看看它是否包含键
/it
,以及值
/FreeTextCallout
,如果是,则将
/Contents
的值作为如下字符串:

if (curAnnot.Contains(PdfName.IT))
{
    if (curAnnot.Get(PdfName.IT)==PdfName.FREETEXTCALLOUT)
    {
        Console.Writeline(curAnnot.Get(PdfName.CONTENTS).ToString());
    }
}

但是似乎没有一个
PdfName.IT
PdfName.FREETEXTCALLOUT
。如何检查
/IT
的存在并检索其值

您可以使用
PdfName
上的构造函数创建自己的
PdfName
对象:

new PdfName("IT");
因此:

new PdfName("IT");
var myPdfNameIT = new PdfName("IT");
if (curAnnot.Contains(myPdfNameIT)) {
    //...
}