Hi ,
This is my code:
import java.util.Iterator;
import com.aspose.pdf.Document;
import com.aspose.pdf.TextFragment;
import com.aspose.pdf.TextFragmentAbsorber;
import com.aspose.pdf.TextFragmentCollection;
public class SearchReplace_1 {
static Document pdfDocument = new Document("C:/temp/v1.pdf");
public static void Text(TextFragmentAbsorber txc, String replace ){
// Accept the absorber for first page of document
pdfDocument.getPages().accept(txc);
TextFragmentCollection textFragmentCollection = txc.getTextFragments();
Iterator it = textFragmentCollection.iterator();
while (it.hasNext())
{
TextFragment textFragment=(TextFragment)it.next();
textFragment.setText(replace);
}
}
public static void main(String[] args) {
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("[BUYER]");
//TextReplaceOptions Code
pdfDocument.getPages().accept(textFragmentAbsorber);
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
Text(textFragmentAbsorber,"XXXXXXXXXX");
pdfDocument.save("C://temp/Modified.pdf");
System.out.println("********* Process Completed *********");
}
}
The above code is working properly and able to relplace the text, but text is overlapping.
I found TextReplaceOptions & ReplaceAdjustmentAction class will avoid this issue , but I am not able to use this code and getting compilation error.
for Issue : Attached input and output file. Could you please help me how to use the TextReplaceOptions & ReplaceAdjustmentAction in above code after the line TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("[BUYER]");
.NET Version Code for same Issue:
textFragmentAbsorber.TextReplaceOptions.ReplaceAdjustmentAction = TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation
Please provide the same for Java too,
Jar used : aspose-pdf-jdk14, aspose-pdf-jdk16
Thanks