试图读取标注,如何从iTextSharp的获得PdfDictionary的/ IT价值? [英] Trying to read callouts, how to get value of /IT from PdfDictionary in iTextSharp?

查看:1225
本文介绍了试图读取标注,如何从iTextSharp的获得PdfDictionary的/ IT价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在PDF阅读标注文本框。我使用iTextSharp的通过所有的注解迭代如下:

I want to read the callout text boxes in a PDF. I'm using iTextSharp to iterate through all the annotations as follows:

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);
            }
        }
    }



检查的HashMap curAnnot >,我看到,当我到达的注释,是一个标注文本框,词典包括以下键值对:

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:

{[/IT,/FreeTextCallout]}
{[/Contents,xyz this is a callout]}

所以,我想我应该做的是检查每一个注释,看它是否包含键 / IT 与值 / FreeTextCallout ,如果是这样,得到的 /内容的值像字符串这样:

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:

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



但似乎没有成为一个 PdfName.IT PdfName.FREETEXTCALLOUT 。我该如何检查 / IT 的存在,并检索其价值?

But there doesn't seem to be a PdfName.IT or PdfName.FREETEXTCALLOUT. How do I check for the existence of /IT and retrieve its value?

推荐答案

您可以通过在构造函数创建自己的 PdfName 对象 PdfName

You can create your own PdfName objects using the constructor on PdfName:

new PdfName("IT");



所以:

So:

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

这篇关于试图读取标注,如何从iTextSharp的获得PdfDictionary的/ IT价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆