We’re trying to take a TextFragment found when searching through a document, cut off some text at the end, and color/link that text. Using IsolateTextSegments with either a startIndex greater than zero, or using the full text length (and not actually isolating anything) works correctly. If you try to isolate just the beginning portion of the fragment, segments get created correctly. But updating anything on the TextState property of those segments will throw a null reference error within the Aspose.PDF library
// Works
//var segments = fragment.IsolateTextSegments(0, fragment.Text.Length);
//var segments = fragment.IsolateTextSegments(1, fragment.Text.Length - 1);
// Does not work
var segments = fragment.IsolateTextSegments(0, fragment.Text.Length - 1);
// In all cases, segments.Count == 1, and segments[1].Text is correct. Exceptions happen here:
segments[1].TextState.ForegroundColor = Aspose.Pdf.Color.Red;
segments[1].TextState.Underline = true;
Exception:
image.png (32.8 KB)
Is there something else that needs to be done to properly initialize TextState, or otherwise prevent the null reference exception?