Getting the error "Invalid index: index should be in the range [1..n] where n equals to the operators count."

I’m trying to replace some text in a pdf document but i keep getting the error “Invalid index: index should be in the range [1…n] where n equals to the operators count.” that I don’t understand.

This only occurs on long documents (90pages+), 1 or 2 pages documents work out fine.

Here is the java code I use :
public static void modif(Document doc, String search, String replace) {
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(search);
for (TextFragment textFragment : (Iterable) textFragmentAbsorber.getTextFragments()) {
TextFragmentState state = textFragment.getTextState();
“search” is the string I want to replace and “replace” is its replacement.

Can you help me please ?


Thanks for contacting support.

Could you kindly share your sample PDF document with us. We will test the scenario in our environment and address it accordingly.

Thank you for your help, but I’m afraid that these documents are confidential and are used for business.

Do you have another solution ? I’m still trying to figure it out by myself

Nevermind, here is a document we use

Thakns for you help
13062019_NEGOCE.pdf (349.9 KB)


Thanks for sharing requested file.

Please also share the values of search and replace string so that we can test the scenario accordingly.

I’m trying to replace :
“RCS NANTERRE 353 311 525 / SIRET 353 311 525 00300 / TVA Intracommunautaire FR 67 353 311 525 / APE 3101 Z.” with “RCS NANTERRE 851 140 095 / SIRET 851 140 095 00015 / TVA Intracommunautaire FR 57 851 140 095 / APE 3101 Z.”
and “S.A au Capital de 8 000 0000 Euros / Siège Social: Espace Néoffice, 24-25 Quai Carnot - 92210 St Cloud Cedex.” with “S.A.S au Capital de 10 000 0000 Euros / Siège Social: Espace Néoffice, 24-25 Quai Carnot - 92210 Saint Cloud”


Thank you for sharing requested information.

We have worked with the data shared by you and have been able to reproduce the issue in our environment. A ticket with ID PDFJAVA-38633 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

Hello, is there any advancement on my issue after two weeks ?


Please note that the ticket has been logged under free support model and will be investigated on first come first serve basis. Therefore, it may take some months to resolve. As soon as we have some definite updates or ETA regarding ticket resolution, we will let you know.

Moreover, we also offer Paid Support , where issues are used to be investigated with higher priority. Our customers, who have paid support subscription, report their issue there which are meant to be investigated urgently. In case your reported issue is a blocker, you may please consider subscribing for Paid Support. For further information, please visit Paid Support FAQs .

The issues you have found earlier (filed as PDFJAVA-38633) have been fixed in Aspose.PDF for Java 19.7.