Aspose PDF Java : Issue while Trying to use TextReplaceOptions

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

We are working on a pdf templates where in we are replacing the placeholders with the database value.

Question is how to dynamically edit the spaces within the paragraph.
While replacing a text in a paragraph, it is creating a space if the replaced text length is lesser than the actual text.

So We wish to know how can we remove the extra spaces.

Example:

Bank's records reflect that a credit card account ending in account number 2150 (the “Account”) was sold to XXXXXXXXXXXX on or about 09-33-2014 . At the time the Account was sold, bank prepared and forwarded to a spreadsheet reflecting Account information as of the sale date based on bank’s records, including, among other things, the Account number, Account balance, the date of the last payment, the Account holder’s name, and number (the “Account Information”). The Account Information reflects that the Account was opened on 06-09-1989 . The Account Information reflects that the Account holder's name at time of the sale was , with a number ending: xxx-xx-YYYY .

Do you have any updates on the above query. As we are in the important phase of our project, It would be very helpful if you could help us on the above.


Also we noticed that a ticket is logged with PDFNEWJAVA-34411 for the issue above.
Please let us know the progress of the above issue log.

We found that the above issue resolution is available in Aspose pdf .NET


textFragmentAbsorber.TextReplaceOptions.ReplaceAdjustmentAction = TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation

Currently we were not able to find the Replace adjustment action is not available in the version Aspose pdf java 9.3.0
Please let us know which Aspose-Java version would have the above funtionality and also share us the link from which we could download the latest jar.

Hi Srinivas,


Sorry for the inconvenience caused. Please download and use latest version of Aspose.Pdf for Java 9.5.0. It adjust space automatically in text replacement. Please find sample output for reference.

Best Regards,

Could you please share some example code that will help us?

TextReplaceOptions textReplaceOptions=new TextReplaceOptions(ReplaceAdjustment.WholeWordsHyphenation,Scope.REPLACE_FIRST);


textFragmentAbsorber.setTextReplaceOptions(textReplaceOptions);

Unable to find the ReplaceAdjustment and setTextReplaceOptions in the
aspose-pdf-9.5.0-jdk16.jar

Please confirm us on the above and also please provide us the code snippet on how to achieve it

We found that the above issue resolution is available in Aspose pdf .NET

textFragmentAbsorber.TextReplaceOptions.ReplaceAdjustmentAction = TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation

Currently we were not able to find the Replace adjustment action is not available in the version Aspose pdf java 9.3.0

Please let us know which Aspose-Java version would have the above funtionality and also share us the link from which we could download the latest jar.

Hi Srinivas,

Thanks for contacting support.

The feature to replace text and re-arrange page contents in order to avoid extra space or content overlapping issue was logged as PDFNEWNET-29860 and is implemented in Aspose.Pdf for .NET 9.6.0. See Text Replacement should Automatically Re-arrange Page Contents section over this [blog post]https://blog.aspose.com/2014/09/18/change-page-orientation-single-resultant-html-with-all-resources-rearrange-page-contents-after-text-replace-and-much-more-with-aspose.pdf-for-.net-9.6.0). However, in order to support similar feature in Aspose.Pdf for Java, we have logged this requirement as PDFNEWJAVA-34490 in our issue tracking system. We will further look into the details of this requirement and will keep you posted on the status of correction. Please be patient and spare us little time.

Any ETA on when this will be available for JAVA ? Approximate date?

srinivas.dasari@citi.com:
Could you please share some example code that will help us?
Hi Srinivas,

I have again tested the scenario using following code snippet and as per my observations, the contents inside PDF are overlapping. For the sake of correction, I have separately logged this problem as PDFNEWJAVA-34491 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. As shared earlier, the implementation of PDFNEWJAVA-34490 will surely help in resolving this problem.

We are sorry for this inconvenience.
srinivas.dasari@citi.com:
Any ETA on when this will be available for JAVA ? Approximate date?
Hi Srinivas,

As we just have logged this requirement, so development team requires little time to investigate and analyze the implementation of this feature based on their current development schedule. Furthermore, as a similar feature is already implemented in Aspose.Pdf for .NET, so the introduction of this feature in Aspose.Pdf for Java will take a bit less time but I am afraid currently we cannot share any ETA. As soon as the feature becomes available, we will be more than happy to update you with the status of correction.

Your patience and comprehension is greatly appreciated in this regard.
Hi Srinivas,

srinivas.dasari@citi.com:
Could you please share some example code that will help us?

Thanks for your feedback. Please find the code I used for the the testing with Aspose.Pdf for Java 9.5.0. We will appreciate it if you please share your sample document as well, It will help us to investigate the issue.

// open document

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(myDir

+ "Lorem_lpsum.pdf");

// create TextAbsorber object to find all instances of the input search

// phrase

com.aspose.pdf.TextFragmentAbsorber textFragmentAbsorber = new com.aspose.pdf.TextFragmentAbsorber(

"popularised");

// accept the absorber for first page of document

pdfDocument.getPages().accept(textFragmentAbsorber);

// get the extracted text fragments into collection

com.aspose.pdf.TextFragmentCollection textFragmentCollection = textFragmentAbsorber

.getTextFragments();

// get first occurrence of text and replace

com.aspose.pdf.TextFragment textFragment = textFragmentCollection

.get_Item(1);

// update text and other properties

textFragment.setText("XXX");

// save updated PDF file

pdfDocument.save(myDir + "Text_Updated.pdf");


We are sorry for the inconvenience caused.


Best Regards,

We are attaching the sample template that you use and share us the generated output pdf. Please find the placeholder and their corresponding values to be replaced.


Placeholder Value1 Value2
[ACCT] 1234 123456677
[BYRNAME] KARTHIK KARTHIKEYANDURGARMAN
[SLEDTE] 12-12-2012
[DEBTRNAME] ENTERPRISESOLNCORP ENTER

please generate the 2 output sheets with the value1 and value 2.
Also share us the files and code snippet.

Hi Srinivas,


Thanks for sharing your sample document. Please find sample code and output files with both set of values. Replaced text is being adjusted properly to fit and words are also being wrapped to new line to keep paragraph formatting, using WholeWordsHyphenation value of ReplaceAdjustment enum. Please download and try latest version of Aspose.Pdf for Java i.e 9.5.0, it will resolve the issue.

Please feel free to contact us for any further assistance.

Best Regards,

The issues you have found earlier (filed as PDFNEWJAVA-34491) have been fixed in Aspose.Pdf for Java 9.7.1.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
(2)

The issues you have found earlier (filed as PDFNEWJAVA-34490) have been fixed in Aspose.Pdf for Java 10.2.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
(1)