Free Support Forum - aspose.com

I am unable to loop through all the annotations using latest aspose pdf 19.3 version


#1

Hi All,

I am trying to read all the annotations in the pdf file using aspose pdf 19.3 version by .net frame work.i am able to get the count as 41 but only 4 of them i can loop .please suggest me the solution to load all the comments.i am attaching the sample pdf doc i am using and code snippet.

Document pdfDocument = new Document(fileName);
StringBuilder strbannotation = new StringBuilder();
string coment = “”;
// Loop through all the annotations
for (int i = 1; i <= pdfDocument.Pages.Count; i++)
{
//AnnotationCollection annotation = (AnnotationCollection)pdfDocument.Pages[1].Annotations;
foreach (Annotation annotation in pdfDocument.Pages[i].Annotations)
{
string s = string.Format("{0} Page: {1} ; Title: {2} ; Subject : {3} ; Contents :{4} \n", coment,i, annotation is MarkupAnnotation ? ((MarkupAnnotation)annotation).Title : string.Empty,

annotation is MarkupAnnotation ? ((MarkupAnnotation)annotation).Subject : string.Empty,

annotation.Contents);
                // Get annotation properties
                Console.WriteLine(s);
               
                //Console.WriteLine("Title : {0} ", annotation.FullName);
                //Console.WriteLine("Subject : {0} ", annotation.Name);
                //Console.WriteLine("Contents : {0} ", annotation.Contents);
                // Console.WriteLine("Inreplies:{0}",annotation.)
            }
        }
        Console.ReadLine();

#2

@madhubabuponugupati

Thanks for contacting support.

Would you please make sure to use valid license before extracting annotations from your PDF. In case you do not have one, you can apply for 30-days free temporary license in order to evaluate the API. Furthermore, we are unable to find any attachment with your post. Would you please upload sample PDF document using upload button in Post Editor. We will test the scenario in our environment and address it accordingly.


#3

attaching the test doc used for testing Test.pdf (33.3 KB)


#4

@madhubabuponugupati

Thanks for sharing sample PDF.

We have tested the scenario in our environment using following code snippet and Aspose.PDF for .NET 19.3. We were not able to replicate the issue that you have mentioned. All annotations were extracted without throwing any exception. For your kind reference, a part of console output is also shared.

Document doc = new Document(dataDir + "Test.pdf");
foreach(Page page in doc.Pages)
{
 foreach(Annotation annot in page.Annotations)
 {
  Console.WriteLine("Annotation Type: " + annot.AnnotationType);
 }
}

Annotations.png (1.7 KB)

Would you please share a sample console application with us which is able to replicate the issue. We will again test the scenario in our environment and address it accordingly.

Please try to modify above condition as well because your document contains FreeText, Text and Popup Annotations.


#5

Hi ali,

please find the screen shot of annotations i am able to extract from the code you have mentioned.Test.PNG (48.7 KB)

image.png (8.1 KB)

Regards,
Madhu


#6

Hi Ali,

In the above screen shot fileName parameter is the name of the file which i have shared with you.

Regards,
Madhu


#7

@madhubabuponugupati

It seems trial version limitation of the API where you can only get/process 4 elements of any collection.

As requested earlier, would you please try using a valid license before making any call to API method. In order to set license, please visit Licensing article(s) in API documentation.