Dear Aspose Team,
I am facing issue while replacing text in PDF.
Issue : I am able to replace text but the text’s are overlapping.
Code Which I used attached:
SearchReplace.java - Using PDFcontentEditor
SearchReplace_1.java - Using TextFragmentAbsorber
Input PDF and output PDF image too attached and I am using 9.3.0 aspose java version.
I saw your forum and this issue was fixed for .NET version:
We are facing the same kind of issue for Java version : Could you please check and let me know whether the same issue fix is there for java and let me know the version to avoid the above issue.
Update: I tried with below code using TextReplaceOption and ReplaceAdjustment is java , still facing same issue. Can anyone please let me know how to avoid overlapping issue.
JAR : aspose-pdf-9.5.0-jdk16.jar
/
*
/
package de.vogella.itext.write;
import java.util.Iterator;
import com.aspose.pdf.;
import com.aspose.pdf.TextReplaceOptions.ReplaceAdjustment;
import com.aspose.pdf.TextReplaceOptions.Scope;
/
* @author 387516
/
public class SearchReplace_1 {
/
* @param args
/
static Document pdfDocument = new Document(“C:/CBWO/PDF/temp/Asset Sale- Cards 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 textReplaceOptions=new TextReplaceOptions(ReplaceAdjustment.WholeWordsHyphenation,Scope.REPLACE_FIRST);
textFragmentAbsorber.setTextReplaceOptions(textReplaceOptions);
//TextReplaceOptions Code
pdfDocument.getPages().accept(textFragmentAbsorber);
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
Text(textFragmentAbsorber,“VENKATESH”);
pdfDocument.save(“C:/CBWO/PDF/temp/Asset Sale- Cards v1_Modified.pdf”);
System.out.println("**** Process Completed *********");
}
}
Thanks,