@srimanta
It is to inform you that the issue which you are facing is actually not a bug in Aspose.PDF. So, we have closed this issue (PDFJAVA-41063) as ‘Not a Bug’.
Your PDF document is searchable and it contains scans as images covered with invisible text used special OCR hidden font. Please check SpecialInvisibleFont.png (134.0 KB)
and DocumentStructure.png (115.2 KB).
The text is replaced in the PDF and can be found but visually you still see old text, because it is on image. We recommend you to use RedactionAnnotation
to clear old text from image and add a new text with required values with the following code example.
Document pdfDocument = new Document(MyDir+"Loan Application - Signed.pdf");
// Create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("3.875");
// Accept the absorber for first page of document
pdfDocument.getPages().accept(textFragmentAbsorber);
// Get the extracted text fragments into collection
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
// Loop through the fragments
for (TextFragment textFragment : (Iterable<TextFragment>) textFragmentCollection) {
// Update text and other properties
System.out.println("found: ="+textFragment.getText());
Page page = textFragment.getPage();
float fontSize = textFragment.getTextState().getFontSize();
System.out.println("font name: ="+textFragment.getTextState().getFont().getFontName());
Rectangle rectangle = textFragment.getRectangle();
System.out.println(rectangle);
System.out.println(textFragment.getPosition());
Rectangle redactRectangle = new Rectangle(
rectangle.getLLX()-1, rectangle.getLLY()-1,
rectangle.getURX()+1, rectangle.getURY()+1);
RedactionAnnotation annotation = new RedactionAnnotation(page, redactRectangle);
annotation.setFillColor(Color.getWhite());
annotation.setColor(Color.getWhite());
annotation.redactExact();
page.getAnnotations().add(annotation);
page.flatten();//this code will delete text and part of image
//we should add a new textFragment using visible font
TextFragment tf = new TextFragment("4.875");
tf.setRectangle(rectangle);
//2 is correction to reduce baseline difference between fonts.
tf.setPosition(new Position(rectangle.getLLX(),rectangle.getLLY()-2));
tf.getTextState().setFontSize(fontSize);
tf.getTextState().setFontStyle(FontStyles.Bold);
page.getParagraphs().add(tf);
}
// Save the updated PDF file
pdfDocument.save(MyDir+"21.11.pdf");