I am trying to add a rectangle annotation programmatically to a pdf document.
Rectangle bounds = new Rectangle(0, 0, 100, 100);
ShapeAnnotation shapeAnnotation = new ShapeAnnotation(ShapeAnnotationType.Rectangle, 1, bounds);
shapeAnnotation.Settings.StrokeColor = Color.Red;
var fileStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("CustomRenderer.Form-1040.pdf");
pdfViewerControl.LoadDocument(fileStream);
pdfViewerControl.AddAnnotation(shapeAnnotation);
The PDF loads correctly if I do not add the annotation, but produces a Null Reference Exception when I add the annotation. I can't se what part is throwing the null reference exception because it is not my code. I am using Syncfusion.Xamarin.SfPdfViewer 19.3.0.48 and Syncfusion.Xamarin.Pdf 19.3.0.48.
Edit: I think the issue is if I add the annotation in the constructor of the MainPage. If I add the annotation later, it works.