Search text in Aspose.PDF

Hai,

I am trying search for a text in PDF Document.
Here I am sharing the code I have used:

                  TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("Verify if the required paperwork (Original Death Certificate and Court Documents, if ", new TextSearchOptions(true));

                            doc.Pages.Accept(textFragmentAbsorber);

But when I do this:
I am getting an error like ,
System.Text.RegularExpressions.RegexParseException: 'Invalid pattern 'Verify if the required paperwork (Original Death Certificate and Court Documents, if ’ at offset 87. Not enough )‘s.’

what dose it mean, and how to solve this?

@pooja.jayan

I request you to set TextSearchOptions(false) because it is set to true when you want to search using regular expression.

Hai,
Thank You for your response.

Solution worked!

But I have one more issue now:
My input text I want to search and highlight is:

“The first step of the process verify member’s card(s). Enter the
member number and click [Search] to bring in all cards.”

TextFragment Absorber throws “{“Invalid index: index should be in the range [1…n] where n equals to the text fragments count.”” exception when there is brackets in input string, Could you please help me to solve this problem?

My code:

             String inputData ="The first step of the process verify  member’s card(s). Enter 
                                            the  member number and click [Search] to bring in all cards.";
              string formattedLine = Regex.Replace(inputData , @"\s+", " ").Replace(" ", @"\s+");

                TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(formattedLine , new TextSearchOptions(true));

                doc.Pages.Accept(textFragmentAbsorber);

                foreach (var textsegment in textFragmentAbsorber.TextFragments[1].Segments)
                {
                    HighlightAnnotation ha = new HighlightAnnotation(textFragmentAbsorber.TextFragments[1].Page, textsegment.Rectangle);
                    ha.Color = Color.Yellow;
                    doc.Pages[textFragmentAbsorber.TextFragments[1].Page.Number].Annotations.Add(ha);
                }

@pooja.jayan

It’s good to know that suggested option has proved to be working on your end. I request you to share the sample PDF file for our investigations.

Hi,
Thankyou for your response.

Here I am sharing you a sample document where I encountered the same issue:
demo.pdf (300.9 KB)

Text I want to search and highlight:

“There are assessment items other than essay questions that require students to construct responses (e.g., short answer, fill in the blank). Essay questions are different from these other constructed response items because they require more systematic and in-depth thinking.”;

I have used the same Code I have shared with you.
If I try string having no brackets, It is working.

TextFragment Absorber is throwing error when words with brackets are found, otherwise it is working

And the same happens with “$” also.

Try to help me solve this.

@pooja.jayan

A ticket with ID PDFNET-50696 has been created in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.