PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Replace FreeText Annotation Contents
http://forum.pdfsharp.com/viewtopic.php?f=2&t=4413
Page 1 of 1

Author:  Duncan_McCloud [ Sun Jan 15, 2023 6:40 pm ]
Post subject:  Replace FreeText Annotation Contents

Hi everyone,
I am trying to replace a FreeText Annotation Contents, but I am facing two issue:

1. The annotation "Contents" is modified only at page #1. Page #2 and Page #3 Annotations are not modified
2. Even if the "Contents" is changed, on the PDF I can still see the old text in the Annotation Rectangle.

This is the code I am using, but still can't get what I am doing wrong.

Code:
string strInputFile = @"F:\DEV\TEST\Input.pdf";
string strOutputFile = @"F:\DEV\TEST\Output.pdf";
// Open the output document
PdfDocument outputDocument = new PdfDocument();
PdfDocument inputDocument = PdfReader.Open(strInputFile, PdfDocumentOpenMode.Import);
// Iterate pages
int count = inputDocument.PageCount;

for (int idx = 0; idx < count; idx++)
{
   // Get the page from the external document...
   PdfPage page = inputDocument.Pages[idx];

   for (int a = 0; a < page.Annotations.Count; a++)
   {
      PdfAnnotation annotation = page.Annotations[a];
      annotation.Contents = "NewValue";
   }
   // ...and add it to the output document.
   outputDocument.AddPage(page);
}

// Save the document...
outputDocument.Save(strOutputFile);


I have attached two sample file here: https://we.tl/t-8d3GE55SxE

Can anyone help me ?

Thanks and Best Regards

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/