We are already getting Latest version aspose library (19.12).
When I try to replace a text “Test” to “Tested” in pptx file,
After replacement I am getting same text is available in a master slides.
Implemented code:
// Initialize License Instance
com.aspose.slides.License license = new com.aspose.slides.License();
// Call setLicense method to set license
license.setLicense(TextReplacer.class.getResourceAsStream("/Aspose.Total.Java.lic"));
//Instantiate the presentation
final FileInputStream fis = new FileInputStream(filePath);
Presentation pptPresentation = new Presentation(fis);
//Get all text boxes in the presentation
ITextFrame[] tb = SlideUtil.getAllTextFrames(pptPresentation, true);
for (int i = 0; i < tb.length; i++)
for (IParagraph para : tb[i].getParagraphs())
for (IPortion port : para.getPortions()) {
String currentSearchString = “Test”
//Find text to be replaced
if (port.getText().contains(currentSearchString)) {
String str = port.getText()
String regex = getEscapeString(currentSearchString);
Pattern pattern = Pattern.compile(regex);
// Step 2: Allocate a Matcher object from the Pattern, and provide the input
Matcher matcher = pattern.matcher(str);
// Step 3: Perform the matching and process the matching result
String outputStr = matcher.replaceAll(toReplace);
port.setText(“Tested”);
}
}
}
/**
- get escape search string
- @param searchString
-
@return special character escape searchString
*/
public static String getEscapeString(String searchString) {
String search_str_esc = escapeRE(searchString);
String[] split = search_str_esc.split("\ “);
String search_pattern = “[\n\r\s\t]+”.join(” ",split);
String pattern = “(?<![\/])” + search_pattern + “(?!\b.(com|co)\b)”;
return pattern;
}