Index and length must refer to a location within the string

Hi Team

I am trying to get all the lines from the pdf but I got error like “Index and length must refer to a location within the string.” This error is not thrown in all pages only in some pages

TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("[^\r\n]+");
TextSearchOptions textSearchOptions = new TextSearchOptions(true);
textFragmentAbsorber.TextSearchOptions = textSearchOptions;
pdfDocument.Pages.Accept(textFragmentAbsorber);


Thanks and Regards
Balamurugan V

Hi Balamurugan,


Please share the resource PDF files causing this issue, so that we can test the scenario in our environment. We are sorry for this inconvenience.

Hi Nayyer Shahbaz

Thanks for your replay. Please find the attached sample
The error occurs only when I Trying to extract line by line
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("[^\r\n]+");
For your reference page no 7, 9, 11 … are showing error

Thanks and Regards
Balamurugan V

Hi Balamurugan,

Thanks for sharing the resource file.

I have tested the scenario using Aspose.Pdf for .NET 10.2.0 and I am unable to notice any issues. Can you please try using the latest release?

[C#]

Document pdfDocument = new Document(@"C:\pdftest\Sample.pdf");

TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("[^\r\n]+");

TextSearchOptions textSearchOptions = new TextSearchOptions(true);

textFragmentAbsorber.TextSearchOptions = textSearchOptions;

pdfDocument.Pages.Accept(textFragmentAbsorber);

// get the extracted text fragments
TextFragmentCollection textFragmentCollection =
textFragmentAbsorber.TextFragments;

// loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{
    Console.WriteLine("Text : {0} ", textFragment.Text);
}

Hi Nayyer Shahbaz

Thanks for your reply its working in version 10.2.0

Thanks and Regards
Balamurugan V

Hi Balamurugan,


Thanks for the feedback.

We are glad to hear that your problem is resolved with latest release. Please continue using our API’s and in the event of any further query, please feel free to contact.