0

In a windows store app project i use Syncfusion for WinRT library

i have this code to add annotations to a pdf page

                ....
                var page = pdfDocument.Pages[pagn];
                ....
                string pdfAnnotationMsg = "Test Annotation 123";
                PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF((float)x, (pageHeight * 1.325f) - (float)y - VertOff2, 5, 5), pdfAnnotationMsg);
                popupAnnotation.Border.Width = 1;
                popupAnnotation.Open = false;
                popupAnnotation.Border.HorizontalRadius = 1;
                popupAnnotation.Border.VerticalRadius = 1;
                popupAnnotation.Icon = PdfPopupIcon.Comment;
                page.Annotations.Add(popupAnnotation);

The annotation gets added correctly but now im trying to access to its content and location
I have this variable :

PdfLoadedAnnotationCollection annotationCollection = pdfDocument.Pages[0].Annotations;

and its count number shows the correct ammount of annotations, but if i use

annotationCollection[0].Text

i get the following exception:

"A first chance exception of type 'System.NullReferenceException' occurred in Syncfusion.Pdf.WinRT.DLL" Exception

enter image description here

How do i properly get the Text and Location from the diferent Annotations ?

lokusking
  • 7,396
  • 13
  • 38
  • 57
Thought
  • 5,326
  • 7
  • 33
  • 69

1 Answers1

1

Annotations will be added only after saving the PDF document, Please save the PDF document before loading the Annotation collection. I have attached the code snippet for your reference.

        var page = doc.Pages[pagn];
        string pdfAnnotationMsg = "Test Annotation 123";
        PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF((float)x, (pageHeight * 1.325f) - (float)y - VertOff2, 5, 5), pdfAnnotationMsg);
        popupAnnotation.Border.Width = 1;
        popupAnnotation.Open = false;
        popupAnnotation.Border.HorizontalRadius = 1;
        popupAnnotation.Border.VerticalRadius = 1;
        popupAnnotation.Icon = PdfPopupIcon.Comment;
        page.Annotations.Add(popupAnnotation);

        //Save the PDF document
        MemoryStream ms=new MemoryStream();
        doc.Save(ms);
        doc.Close(true);

        //Load the PDF document again
        doc = new PdfLoadedDocument(ms);
        PdfLoadedAnnotationCollection annotationCollection = doc.Pages[0].Annotations;
        var text = annotationCollection[0].Text;

Please let us know if you have any concern.