如何更新注释内容

时间:2019-09-27 04:04:11

标签: c# pdf annotations itext

我获得了注释的内容,但是我不知道如何更新内容,并且在生成pdf时应该是新值

我找到了这个https://itextpdf.com/en/resources/examples/itext-7/replacing-pdf-objects,但是问题是这是用Java制作的

PdfPage anonPage = pdf.GetPage(1);
PdfDictionary pageDict = pdf.GetPage(1).GetPdfObject();
PdfAnnotation ann   = new PdfTextAnnotation(pageDict);
PdfArray annotArray = pageDict.GetAsArray(PdfName.Annots);
   for (int i = 0; i < annotArray.Size(); ++i)
            {
                PdfDictionary curAnnot = annotArray.GetAsDictionary(i);
                PdfString contents = curAnnot.GetAsString(PdfName.Contents);

            //Gets the value from the comment
            if (!string.IsNullOrWhiteSpace(contents?.ToString()))
            {
                if (contents.ToString().Contains("Printed"))
                {
                    curAnnot.Put(PdfName.CONTENTS, new PdfString("value has been changed"));
                    Console.WriteLine(contents);
                }
                else
                { Console.WriteLine(contents); }
            }
        }

0 个答案:

没有答案