Hi,
I am using Java Aspose-pdf (21.11) licensed version. After replacing the text in the PDF with a very long text, the updated text is not getting wrapped to multiple lines.
Followed the suggestion from,
TxtReplace.pdf => source pdf TxtReplace.pdf (6.2 KB)
TxtReplace1693248536421.pdf => text replaced pdf TxtReplace1693248536421.pdf (70.8 KB)
My code is as below,
final Document document = new Document("TxtReplace.pdf");
final TextFragmentAbsorber fragmentAbsorber = new TextFragmentAbsorber("{{Name}}");
fragmentAbsorber.getTextSearchOptions().setRegularExpressionUsed(false);
TextSearchOptions textSearchOptions = new TextSearchOptions(false);
fragmentAbsorber.setTextSearchOptions(textSearchOptions);
`fragmentAbsorber.getTextReplaceOptions().setReplaceAdjustmentAction(TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation);`
document.getPages().accept(fragmentAbsorber);
final TextFragmentCollection textFragments = fragmentAbsorber.getTextFragments();
if (textFragments.size() == 0)
return;
fragmentAbsorber.reset();
for (final TextFragment fragment : textFragments)
{
fragment.setText("BEGIN- ReplacedText ReplacedText ReplacedText ReplacedText ReplacedText ReplacedText ReplacedText ReplacedText ReplacedText ReplacedText ReplacedText ReplacedText-END");
}
document.save("TxtReplace" + System.currentTimeMillis() + ".pdf");