Hi,
I am trying to find a word in the pdf and replacing that word with that many unicode characters.
I am using font as Courier as Arial is not available.
It is overlapping with other words next to it even though i set the ReplaceAdjustment.ShiftRestOfLine.
In below example the unicode char used is ₩ U+20A9.
Mac it is overlapping and linux it is giving exceptions…
java.lang.NullPointerException: null
at com.aspose.pdf.internal.l5y.l1j.l3j(Unknown Source)
at com.aspose.pdf.TextState.setFont(Unknown Source)
at com.aspose.pdf.TextFragmentState.setFont(Unknown Source)
please find my code… Java program
Document pdfDocument = new Document(new FileInputStream(inFilePath));
pdfDocument.optimize();
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(“supposed”);
TextSearchOptions textSearchOptions = new TextSearchOptions(true);
textFragmentAbsorber.setTextSearchOptions(textSearchOptions);
TextReplaceOptions textReplaceOptions = new TextReplaceOptions();
textReplaceOptions.setReplaceAdjustmentAction(ReplaceAdjustment.ShiftRestOfLine);
textFragmentAbsorber.setTextReplaceOptions(textReplaceOptions);
pdfDocument.getPages().accept(textFragmentAbsorber);
String actedText = getActedText(“supposed”, ‘\u20A9’);
// Get the extracted text fragments into collection
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
for (TextFragment textFragment : (Iterable) textFragmentCollection) {
float size = textFragment.getTextState().getFontSize();
textFragment.getTextState().setFont(FontRepository.findFont(“Courier”));
textFragment.getTextState().setFontSize(size);
textFragment.getTextState().setForegroundColor(com.aspose.pdf.Color.getBlack());
textFragment.setText(actedText);
}
pdfDocument.save(new FileOutputStream(outFilePath));test_acted.pdf (50.8 KB)
test.pdf (20.0 KB)