Hi Aspose Support,
I am trying to replace text from the pdf file, but it is giving exception, and also thread is blocked on the server due to high time taking. Aspose.pdf version 23.11 is using. please check
java.lang.NullPointerException: Cannot invoke “com.aspose.pdf.internal.l21u.l18n.lv()” because the return value of “com.aspose.pdf.internal.l6u.l0y.l0y()” is null
at com.aspose.pdf.internal.l6j.lu.lI(Unknown Source)
at com.aspose.pdf.internal.l6h.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l6n.lI.lI(Unknown Source)
at com.aspose.pdf.TextSegment.setText(Unknown Source)
at com.aspose.pdf.TextFragment.setText(Unknown Source)
at com.aspose.pdf.facades.PdfContentEditor.replaceText(Unknown Source)
at com.aspose.pdf.facades.PdfContentEditor.replaceText(Unknown Source)
at com.aspose.pdf.facades.PdfContentEditor.replaceText(Unknown Source)
1520615529927-M Cohen Resume.pdf (39.3 KB)
image.png (18.7 KB)
@praveenrchilli
Using below code snippet with 24.1 version of the API, we could not notice any issues. Can you please try it with the latest version and let us know if issue still persists. Also, please make sure that all fonts are installed in the system which are being used in the PDF:
Document pdfDocument = new Document(dataDir + "1520615529927-M Cohen Resume.pdf");
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("Monique Marie Cohen");
// Accept the absorber for all pages of the document
pdfDocument.getPages().accept(textFragmentAbsorber);
// Get the extracted text fragments into a collection
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
// Loop through the fragments
for (TextFragment textFragment : textFragmentCollection) {
// Set the text fragment to be an inline paragraph
textFragment.setInLineParagraph(true);
// Update text and other properties
try {
textFragment.setText("Aspose Pty Ltd");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
pdfDocument.save(dataDir + "24.1.pdf");
24.1.pdf (40.0 KB)