Unable to read all annotations from pdf document

Using Adobe Acrobat, I added various annotations to a PDF. However, the Aspose library appears unable to read all of them, specifically those annotations created within Adobe Acrobat.

I have attached referral documents and a code snippet

Source document - AnnotationSourceDocument.pdf
Output document - AnnotationSourceDocument_output.pdf
AnnotationSourceDocument.pdf (213.1 KB)

AnnotationSourceDocument_output.pdf (210.9 KB)

AddAnnotation.pdf (124.8 KB)

   public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
            Document pdfDocument = new Document(dataDir + "AnnotationSourceDocument.pdf");
            Document pdfDocumentNew = new Document(dataDir + "AddAnnotation.pdf");
            int index = 1;
            foreach (var page in pdfDocument.Pages)
            {
                Console.WriteLine("Page" + index);
                  foreach (var annotation in page.Annotations)
                {
                    if (annotation == null || String.IsNullOrWhiteSpace(annotation.Contents)) continue;
                    Console.WriteLine(annotation.AnnotationType);
                    Console.WriteLine("Contents : {0} ", annotation.Contents);
                    Console.WriteLine("Contents : {0} ", annotation.Rect);                
                    TextAnnotation textAnnotation = new TextAnnotation(page, annotation.Rect);
                    textAnnotation.Contents = annotation.Contents;
                    textAnnotation.Open = true;
                    textAnnotation.Flags = 0;
                    textAnnotation.Icon = TextIcon.Key;
                    Border border = new Border(textAnnotation);
                    border.Width = 5;
                    border.Dash = new Dash(1, 1);
                    textAnnotation.Border = border;
                    textAnnotation.Rect = annotation.Rect;
                    pdfDocumentNew.Pages[index].Annotations.Add(textAnnotation);
                }
                index++;
            }  
            dataDir = dataDir + "AnnotationSourceDocument_output.pdf";
            pdfDocumentNew.Save(dataDir);
        }

@rajeev.francis
If you remove the Contents check in the annotation iteration cycle

//if (annotation == null || String.IsNullOrWhiteSpace(annotation.Contents)) continue;
if (annotation == null) continue;

then information about 8 annotations on the first page and six on the second will be displayed, which is the same as what Acrobat shows.
2.png (51.9 KB)

Hi Sergei,

Thank you for the update.

As you mentioned in the thread, if we remove the null condition check, the iteration will occur, but the object will have no content. How can I retrieve the content from the object?

image.png (133.3 KB)

@rajeev.francis
For some annotations in the attached document (like PopupAnnotation-s), Content is not specified.
Here is an excerpt from the pdf specification 3.png (65.2 KB)

Hi Sergi,

All contents are visible in the browsers as well as Adobe Acrobat,

Adobe Acrobat.
image.png (18.6 KB)

Browser view

image.png (9.7 KB)

image.png (9.2 KB)

Not all.
Only with existing content.
4.png (21.4 KB)

Hi Sergei,

The document “AnnotationSourceDocument.pdf” has two pages, The first page contains four annotations and the second has two, both are visible in browsers

On both pages, one annotation is created from Adobe Acrobat and the content is “Content from adobe” and “Adobe 2”.

My issue is that I can’t read the annotation created from Adobe Acrobat.

If you run the application you can see empty content from Adobe annotation but We can see the content in browsers and all other such applications.

I hope you understand my problem regarding this.

@rajeev.francis

Please attach a screenshot(s) for the document “AnnotationSourceDocument.pdf” opened in Acrobat, with marked on it ALL annotations that you believe are not found by the library.

I have attached the screenshot of “AnnotationSourceDocument.pdf” document also with a code snippet

AnnotationSourceDocument.pdf preview
adobe comment’s.png (92.1 KB)

Code snippet
code snippet.png (90.9 KB)

@rajeev.francis

We are checking it and will get back to you shortly.

@rajeev.francis
I am providing a slightly modified version of your code for iterating over document annotations.
My output is as follows WithLicense.png (6.8 KB) - please compare it with yours.
And also - what version of the library are you using?
Previously, demo versions had a limitation of displaying/processing four annotations per page max. In the latest version (24.5), the restrictions are less strict and I have the same output without a license.

var pdfDocument = new Document(dataDir + "AnnotationSourceDocument.pdf");
int index = 1;
foreach (var page in pdfDocument.Pages)
{
    Console.WriteLine("Page: " + index++);
    foreach (var annotation in page.Annotations)
        if (annotation != null)
        {
            string info = "Ann. Type:" + annotation.AnnotationType.ToString() + "\t Contents: ";
            if (!string.IsNullOrWhiteSpace(annotation.Contents))
                info += annotation.Contents;
            else
                info += "None";

            info += ("\t Rect: " + annotation.Rect);

            Console.WriteLine(info);
        }
}

Hi Sergei,

The issue has been resolved after upgrading to the latest package. It was version 24.3.
I appreciate your support.

@rajeev.francis
Glad your question is resolved.
Thank you for your feedback.