We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Using IsolateTextSegments with a startIndex of zero throws exceptions updating TextState

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?

@jjoconnell

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input PDF document.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.