Could you please share your sample PDF document along with sample code snippet. We will test the scenario in our environment and address it accordingly.
Please also share the code snippet that you have tried at your side to replace the text from this document so that we can test the scenario accordingly.
Here is the 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.
I’m trying to replace “Majencia SA” with “Nowy Styl - Majencia”
We were able to replicate the issue in our environment with Aspose.PDF for Java 19.6. Therefore, we have logged it as PDFJAVA-38676 in our issue tracking system for the sake of correction. We will further look into details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.