Hello,
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);
doc.getPages().accept(textFragmentAbsorber);
for (TextFragment textFragment : (Iterable) textFragmentAbsorber.getTextFragments()) {
textFragment.setText(replace);
TextFragmentState state = textFragment.getTextState();
textFragment.getTextState().setFont(state.getFont());
textFragment.getTextState().setFontSize(state.getFontSize());
textFragment.getTextState().setForegroundColor(state.getForegroundColor());
textFragment.getTextState().setBackgroundColor(Color.getWhite());
textFragmentAbsorber.getTextReplaceOptions().setReplaceAdjustmentAction(TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation);
}
}
“search” is the string I want to replace and “replace” is its replacement.
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.
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 .