Hi Fernando,
Hi Fernando,
Thanks for sharing the code snippet.
I have tested the scenario with Aspose.Pdf for Java 10.1.0 while using the following code snippet and I am unable to notice any time consumption issue. Can you please share the complete code snippet so that we can again test the scenario in our environment.
[Java]
String extractedText = "TRANSACTION";
Pattern pattern = Pattern.compile("name:.*?(\\w+\\s\\w+)",
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.UNICODE_CASE);
Matcher matcher = pattern.matcher(extractedText);
while (matcher.find()) {
String toReplace = matcher.group(1).toString();
//System.out.println(toReplace);
com.aspose.pdf.Document pdfDocument = ReplaceTextInPDF(
new com.aspose.pdf.Document("c:/pdftest/sampleJava.pdf"),
toReplace, false, extractedText);
}
private static Document ReplaceTextInPDF(Document pdfDocument, String textToSearch, boolean isPattern, String FileContent){
//Pattern pattern = Pattern.compile(textToSearch);
//Matcher matcher = pattern.matcher(FileContent);
//if (matcher.find()) {
com.aspose.pdf.TextFragmentAbsorber textFragmentAbsorber = new com.aspose.pdf.TextFragmentAbsorber(textToSearch);
if (isPattern) {
com.aspose.pdf.TextSearchOptions textSearchOptions = new com.aspose.pdf.TextSearchOptions(true);
textFragmentAbsorber.setTextSearchOptions(textSearchOptions);
}
pdfDocument.getPages().accept(textFragmentAbsorber);
com.aspose.pdf.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
int total = textFragmentCollection.size();
for (int i = 1; i<=total ; i++) {
TextFragment textFragment = textFragmentCollection.get_Item(i);
textFragment.setText("textToReplace");
}
//}
return pdfDocument;
}
Ok, i will upload a portion of code for you to verify that. Also i have another concern. I open a PDF document, and do not do any changes to it, saves to a specific location, and the images dissapear, just text remains. is there a way to avoid this?
Hi Fernando,
I have tested the scenario using the sample file shared in 617249 and I am unable to notice any issue. The images properly appear in the resultant file. Can you please confirm if you are using a similar file or facing a problem with another document?
[Java]
//Open document
Document doc = new Document("c:\\sample(1).pdf");
//Save resultant document
doc.save("c:\\ReSaved_output.pdf");