[英]Trying to read callouts, how to get value of /IT from PdfDictionary in iTextSharp?
I want to read the callout text boxes in a PDF. 我想阅读PDF中的标注文本框。 I'm using iTextSharp to iterate through all the annotations as follows:
我正在使用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);
}
}
}
Examining the hashMap
of curAnnot
, I see that when I get to an annotation that is a callout text box, the dictionary includes the following key-value pairs: 检查
curAnnot
的hashMap
,我发现当到达标注文本框的注释时,字典包含以下键/值对:
{[/IT,/FreeTextCallout]}
{[/Contents,xyz this is a callout]}
So I think what I should do is check each annotation to see if it includes the key /IT
with the value /FreeTextCallout
and if so, get the value of /Contents
as a string like so: 因此,我认为我应该做的是检查每个批注以查看其是否包含具有值
/FreeTextCallout
的键/IT
,如果包含,则将/Contents
的值作为字符串获取,如下所示:
if (curAnnot.Contains(PdfName.IT))
{
if (curAnnot.Get(PdfName.IT)==PdfName.FREETEXTCALLOUT)
{
Console.Writeline(curAnnot.Get(PdfName.CONTENTS).ToString());
}
}
But there doesn't seem to be a PdfName.IT
or PdfName.FREETEXTCALLOUT
. 但是似乎没有
PdfName.IT
或PdfName.FREETEXTCALLOUT
。 How do I check for the existence of /IT
and retrieve its value? 如何检查
/IT
的存在并获取其值?
You can create your own PdfName
objects using the constructor on PdfName
: 你可以创建自己的
PdfName
使用在构造对象PdfName
:
new PdfName("IT");
So: 所以:
var myPdfNameIT = new PdfName("IT");
if (curAnnot.Contains(myPdfNameIT)) {
//...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.