Browse our Products
Aspose.Slides for Python via Java 24.6 Release Notes
Key | Summary | Category |
---|---|---|
SLIDESPYJAVA-45 | Use Aspose.Slides for Java 24.6 features | Enhancement |
Public API Changes
ITextSearchOptions interface has been added
The new interface, ITextSearchOptions, represents options that can be used to search for text in a Presentation, Slide or TextFrame.
Example:
presentation = Presentation("pres.pptx");
textSearchOptions = TextSearchOptions();
textSearchOptions.setWholeWordsOnly(True);
presentation.replaceText("the", "***", textSearchOptions, None);
presentation.save("pres-out.pptx", SaveFormat.Pptx);
presentation.dispose();
IFindResultCallback interface has been added
The new interface IFindResultCallback contains a callback method that can be used to retrieve search results.
The following code sample demonstrates how to handle text highlighting results using the IFindResultCallback interface:
jpype.addClassPath("./src/FindResult-0.1-SNAPSHOT.jar")
from aspose.callback import FindResultCallback
pres = Presentation("pres.pptx");
# Create callback.
callback = FindResultCallback();
# Highlight all words "address".
pres.highlightText("address", Color.YELLOW, TextSearchOptions(), callback);
# Output the number of found fragments of the given text.
print(callback.getCount());
# Output data for each word "address" found.
for i in range(callback.getCount()):
info = callback.Words.get(i)
print(info.getFoundText() + ", " + str(info.getTextPosition()))
# Get all the data about the found cases in the first slide.
elements = callback.getElementsForSlide(callback.getSlideNumbers()[0]);
pres.save("pres-out.pptx", SaveFormat.Pptx);
pres.dispose();
Due to limitations of jpype, the implementation of the FindResultCallback interface should be imported as Jar using jpype.addClassPath. To do that, you need to create src directory and place this jar to this folder.
Here is an example of the folder structure:
root
|_src
| |_FindResult-0.1-SNAPSHOT.jar
|_example.py
MAVEN project: FindResultProject.zip
IFindResultCallback interface implementation
/**
* Class that provides information about all found occurrences of a given text.
*/
static class FindResultCallback implements IFindResultCallback
{
/**
* Array of retrieved text information.
*/
final List<WordInfo> Words = new ArrayList<>();
/**
* The number of matches found to a given text.
*/
public int getCount()
{
return Words.size();
}
/**
* Gets all slides in which the given text was found.
*/
public Integer[] getSlideNumbers()
{
List<Integer> slideNumbers = new ArrayList();
for (WordInfo element : Words)
{
int slideNumber = ((Slide)element.TextFrame.getSlide()).getSlideNumber();
if (!slideNumbers.contains(slideNumber))
slideNumbers.add(slideNumber);
}
return slideNumbers.toArray(new Integer[0]);
}
/**
* Gets all occurrences of the found text on the slide.
* @param slideNumber Slide number
*/
public WordInfo[] getElementsForSlide(int slideNumber)
{
List<WordInfo> foundElements = new ArrayList<>();
for (WordInfo element : Words)
{
if (((Slide)element.TextFrame.getSlide()).getSlideNumber() == slideNumber)
foundElements.add(element);
}
return foundElements.toArray(new WordInfo[0]);
}
/**
* Callback method that receives data about the found text.
* @param textFrame {@link ITextFrame} where searching text was found.
* @param oldText The Old text
* @param foundText The Found text.
* @param textPosition Position of found text in source text.
*/
public void foundResult(ITextFrame textFrame, String oldText, String foundText, int textPosition)
{
Words.add(new WordInfo(textFrame, oldText, foundText, textPosition));
}
}
/**
* Class providing information about each text found in the presentation.
*/
public static class WordInfo
{
ITextFrame TextFrame;
String SourceText;
String FoundText;
int TextPosition;
WordInfo(ITextFrame textFrame, String sourceText, String foundText, int textPosition)
{
TextFrame = textFrame;
SourceText = sourceText;
FoundText = foundText;
TextPosition = textPosition;
}
/**
* Gets found text.
*/
public String getFoundText() {
return FoundText;
}
/**
* Gets the source text for the TextFrame in which the text was found.
*/
public String getSourceText() {
return SourceText;
}
/**
* The position of the found text in the text frame.
*/
public int getTextPosition() {
return TextPosition;
}
/**
* The text frame in which the text was found.
*/
public ITextFrame getTextFrame() {
return TextFrame;
}
}
ITextFrame.HighlightText() and ITextFrame.HighlightRegex() methods have been added
New methods HighlightText() and HighlightRegex() have been added to the ITextFrame interface and the TextFrame class.
The following code sample shows how to highlight text in a TextFrame:
presentation = Presentation("pres.pptx");
textFrame = presentation.getSlides().get_Item(0).getShapes().get_Item(0).getTextFrame();
# highlighting all words 'important'
textFrame.highlightText("important", Color.BLUE);
textSearchOptions = TextSearchOptions();
textSearchOptions.setWholeWordsOnly(True);
# highlighting all separate 'the' occurrences
textFrame.highlightText("the", Color.MAGENTA, textSearchOptions, None);
presentation.save("pres-out2.pptx", SaveFormat.Pptx);
presentation.dispose();
The following code sample shows how to highlight text using regular expression in a TextFrame:
presentation = Presentation("pres.pptx");
regex = Pattern.compile("\\b[^\\s]{10,}\\b");
# highlighting all words with 10 symbols or longer
presentation.getSlides().get_Item(0).getShapes().get_Item(0).getTextFrame().highlightRegex(regex, Color.BLUE, None);
presentation.save("SomePresentation-out.pptx", SaveFormat.Pptx);
presentation.dispose();
ITextFrame.ReplaceText() and ITextFrame.ReplaceRegex() methods have been added
New methods ITextFrame.HighlightText() and ITextFrame.HighlightRegex() have been added to the ITextFrame interface and the TextFrame class.
The following code sample shows how to replace a specified string with another specified string:
presentation = Presentation("pres.pptx");
textSearchOptions = TextSearchOptions();
textSearchOptions.setWholeWordsOnly(True);
# Replace all separate 'the' occurrences with '***'
presentation.getSlides().get_Item(0).getShapes().get_Item(0).getTextFrame().replaceText("the", "***", textSearchOptions, None);
presentation.save("SomePresentation-out2.pptx", SaveFormat.Pptx);
presentation.dispose();
The following code sample shows how to replace text using regular expressions:
presentation = Presentation("pres.pptx");
regex = Pattern.compile("\\b[^\\s]{5,}\\b");
# Replace all words with 5 symbols or longer with '***'
presentation.getSlides().get_Item(0).getShapes().get_Item(0).getTextFrame().replaceRegex(regex, "***", None);
presentation.save("SomePresentation-out.pptx", SaveFormat.Pptx);
presentation.dispose();
IPresentation.HighlightText() and IPresentation.HighlightRegex() have been added
New methods HighlightText() and HighlightRegex() have been added to the IPresentation interface and the Presentation class.
The following code sample shows to highlight text in a PowerPoint Presentation:
presentation = Presentation("pres.pptx");
textSearchOptions = TextSearchOptions();
textSearchOptions.setWholeWordsOnly(True);
# highlighting all separate 'the' occurrences
presentation.highlightText("the", Color.MAGENTA, textSearchOptions, None);
# highlight all 'abi' character sequences
presentation.highlightText("abi", Color.RED);
presentation.save("pres-out.pptx", SaveFormat.Pptx);
presentation.dispose();
The following code sample shows how to highlight text using regular expressions:
presentation = Presentation("pres.pptx");
regex = Pattern.compile("\\b[^\\s]{10,}\\b");
# highlighting all words with 10 symbols or longer
presentation.highlightRegex(regex, Color.BLUE, None);
presentation.save("pres-out.pptx", SaveFormat.Pptx);
presentation.dispose();
IPresentation.ReplaceText() and IPresentation.ReplaceRegex() methods have been added
New methods ReplaceText() and ReplaceRegex() have been added to the IPresentation interface and the Presentation class.
The following code sample shows how to replace a specified string with another specified string:
presentation = Presentation("pres.pptx");
textSearchOptions = TextSearchOptions();
textSearchOptions.setWholeWordsOnly(True);
# Replace all separate 'the' occurrences with '***'
presentation.replaceText("the", "***", textSearchOptions, None);
presentation.save("SomePresentation-out2.pptx", SaveFormat.Pptx);
presentation.dispose();
The following code sample shows how to highlight text using regular expressions:
presentation = Presentation("pres.pptx");
regex = Pattern.compile("\\b[^\\s]{10,}\\b");
# Replace all words with 10 symbols or longer with '***'
presentation.replaceRegex(regex, "***", None);
presentation.save("SomePresentation-out.pptx", SaveFormat.Pptx);
presentation.dispose();
ISaveOption.GradientStyle property has been added
A new property GradientStyle has been added to the ISaveOption interface and the SaveOption class. It allows users to change the visual rendering style of a two-color gradient. Two options are available:
- GradientStyle.Default - renders the gradient similarly to how it appears when exporting a presentation to an image using PowerPoint.
- GradientStyle.PowerPointUI - renders the two-color gradient according to its appearance in the PowerPoint user interface.
Example:
pres = Presentation("pres.pptx");
options = RenderingOptions();
options.setGradientStyle(GradientStyle.PowerPointUI);
img = pres.getSlides().get_Item(0).getImage(options, 2, 2);
pres.dispose();
Methods have been marked as obsolete
The following methods have been marked as obsolete and will be removed in version 24.10.
- ITextFrame.highlightText(string text, Color highlightColor, ITextHighlightingOptions options)
- ITextFrame.highlightRegex(string regex, Color highlightColor, ITextHighlightingOptions options)
- TextFrame.highlightText(string text, Color highlightColor, ITextHighlightingOptions options)
- TextFrame.highlightRegex(string regex, Color highlightColor, ITextHighlightingOptions options)
Interfaces and classes have been marked as obsolete
The following interfaces and classes have been marked as obsolete and will be removed in version 24.10.
- interface ITextHighlightingOptions
- class TextHighlightingOptions