ITextFrame

All Implemented Interfaces: com.aspose.slides.ISlideComponent

public interface ITextFrame extends ISlideComponent

Represents a TextFrame.

Methods

MethodDescription
getParagraphs()Returns the list of all paragraphs in a frame.
getText()Gets or sets the plain text for a TextFrame.
setText(String value)Gets or sets the plain text for a TextFrame.
getTextFrameFormat()Returns the formatting object for this TextFrame object.
getHyperlinkQueries()Provides easy access to contained hyperlinks.
getParentShape()Returns the parent shape or null if the parent object does not implement the IShape interface Read-only IShape.
getParentCell()Returns the parent cell or null if the parent object does not implement the ICell interface.
joinPortionsWithSameFormatting()Joins runs with same formatting in all paragraphs.
highlightText(String text, Color highlightColor)Highlights all matches of the sample text with the specified color.
splitTextByColumns()Splits the text content of the ITextFrame into an array of strings, where each element corresponds to a separate text column within the frame.
highlightText(String text, Color highlightColor, ITextHighlightingOptions options)Highlights all matches of the sample text with the specified color.
highlightText(String text, Color highlightColor, ITextSearchOptions options, IFindResultCallback callback)Highlights all matches of the sample text with the specified color.
highlightRegex(Pattern regex, Color highlightColor, IFindResultCallback callback)Highlights all matches of the regular expression with the specified color.
highlightRegex(String regex, Color highlightColor, ITextHighlightingOptions options)Highlights all matches of the regular expression with the specified color.
replaceText(String oldText, String newText, ITextSearchOptions options, IFindResultCallback callback)Replaces all occurrences of the specified text with another specified text.
replaceRegex(Pattern regex, String newText, IFindResultCallback callback)Replaces all matches of the regular expression with the specified string.

getParagraphs()

public abstract IParagraphCollection getParagraphs()

Returns the list of all paragraphs in a frame. Read-only IParagraphCollection.

Returns: IParagraphCollection

getText()

public abstract String getText()

Gets or sets the plain text for a TextFrame. Read/write String.

Value: The text.

Returns: java.lang.String

setText(String value)

public abstract void setText(String value)

Gets or sets the plain text for a TextFrame. Read/write String.

Value: The text.

Parameters:

ParameterTypeDescription
valuejava.lang.String

getTextFrameFormat()

public abstract ITextFrameFormat getTextFrameFormat()

Returns the formatting object for this TextFrame object. Read-only ITextFrameFormat.

Returns: ITextFrameFormat

getHyperlinkQueries()

public abstract IHyperlinkQueries getHyperlinkQueries()

Provides easy access to contained hyperlinks. Read-only IHyperlinkQueries.

Returns: IHyperlinkQueries

getParentShape()

public abstract IShape getParentShape()

Returns the parent shape or null if the parent object does not implement the IShape interface Read-only IShape.


The following code sample shows 
 
 Presentation presentation = new Presentation("SomePresentation.pptx");
 try {
     AutoShape autoShape = (AutoShape)presentation.getSlides().get_Item(0).getShapes().get_Item(0);
     Table table = (Table)presentation.getSlides().get_Item(0).getShapes().get_Item(1);

     // These assertions are always true
     Assert.assertTrue(autoShape.getTextFrame().getParentShape() == autoShape);
     Assert.assertTrue((table.get_Item(0,0).getTextFrame()).getParentShape() == null);
 } finally {
     if (presentation != null) presentation.dispose();
 }

Returns: IShape

getParentCell()

public abstract ICell getParentCell()

Returns the parent cell or null if the parent object does not implement the ICell interface. Read-only ICell.


The following code sample shows 
 
 Presentation presentation = new Presentation("SomePresentation.pptx");
 try {
     AutoShape autoShape = (AutoShape)presentation.getSlides().get_Item(0).getShapes().get_Item(0);
     Table table = (Table)presentation.getSlides().get_Item(0).getShapes().get_Item(1);

     // These assertions are always true
     Assert.assertTrue(table.get_Item(0,0).getTextFrame().getParentCell() == table.get_Item(0,0));
     Assert.assertTrue(autoShape.getTextFrame().getParentCell() == null);
 } finally {
     if (presentation != null) presentation.dispose();
 }

Returns: ICell

joinPortionsWithSameFormatting()

public abstract void joinPortionsWithSameFormatting()

Joins runs with same formatting in all paragraphs.

highlightText(String text, Color highlightColor)

public abstract void highlightText(String text, Color highlightColor)

Highlights all matches of the sample text with the specified color.

Parameters:

ParameterTypeDescription
textjava.lang.StringThe text to highlight.
highlightColorjava.awt.ColorThe color to highlight the text.

splitTextByColumns()

public abstract String[] splitTextByColumns()

Splits the text content of the ITextFrame into an array of strings, where each element corresponds to a separate text column within the frame.


The following example demonstrates how to use #splitTextByColumns.splitTextByColumns:
 
 Presentation pres = new Presentation("example.pptx");
 try {
     // Get the first shape on the slide and cast it to ITextFrame
     ITextFrame textFrame = (ITextFrame) pres.getSlides().get_Item(0).getShapes().get_Item(0);
     // Split the text frame content into columns
     String[] columnsText = textFrame.splitTextByColumns();
     // Print each column's text to the console
     for (String column : columnsText)
         System.out.println(column);
 } finally {
     if (pres != null) pres.dispose();
 }

Returns: java.lang.String[] - An array of strings, where each string represents the text content of a specific column in the ITextFrame.


If the text frame does not contain multiple columns, the returned array will have a single element containing the full text. Empty columns will be represented as empty strings in the array.

highlightText(String text, Color highlightColor, ITextHighlightingOptions options)

public abstract void highlightText(String text, Color highlightColor, ITextHighlightingOptions options)

Highlights all matches of the sample text with the specified color.

Parameters:

ParameterTypeDescription
textjava.lang.StringThe text to highlight.
highlightColorjava.awt.ColorThe color to highlight the text.
optionsITextHighlightingOptionsHighlighting options.

highlightText(String text, Color highlightColor, ITextSearchOptions options, IFindResultCallback callback)

public abstract void highlightText(String text, Color highlightColor, ITextSearchOptions options, IFindResultCallback callback)

Highlights all matches of the sample text with the specified color.


The following code sample shows how to highlight text in a TextFrame.
 
 Presentation presentation = new Presentation("SomePresentation.pptx");
 try {
     TextSearchOptions textSearchOptions = new TextSearchOptions();
     textSearchOptions.setWholeWordsOnly(true);
     // highlighting all words 'important'
     ((AutoShape)presentation.getSlides().get_Item(0).getShapes().get_Item(0)).getTextFrame().highlightText("important", Color.BLUE);
     // highlighting all separate 'the' occurrences
     ((AutoShape)presentation.getSlides().get_Item(0).getShapes().get_Item(0)).getTextFrame().highlightText("the", Color.MAGENTA, textSearchOptions, null);
     presentation.save("SomePresentation-out2.pptx", SaveFormat.Pptx);
 } finally {
     if (presentation != null) presentation.dispose();
 }

Parameters:

ParameterTypeDescription
textjava.lang.StringThe text to highlight.
highlightColorjava.awt.ColorThe color to highlight the text.
optionsITextSearchOptionsText search options ITextSearchOptions.
callbackIFindResultCallbackThe callback object for receiving search results IFindResultCallback.

highlightRegex(Pattern regex, Color highlightColor, IFindResultCallback callback)

public abstract void highlightRegex(Pattern regex, Color highlightColor, IFindResultCallback callback)

Highlights all matches of the regular expression with the specified color.


The following code sample shows how to highlight text in a TextFrame using a regular expression.
 
 Presentation presentation = new Presentation("SomePresentation.pptx");
 try {
     Pattern regex = Pattern.compile("\\b[^\\s]{5,}\\b");
     // highlighting all words with 5 symbols or longer
     ((AutoShape)presentation.getSlides().get_Item(0).getShapes().get_Item(0)).getTextFrame().highlightRegex(regex, Color.BLUE, null);
     presentation.save("SomePresentation-out.pptx", SaveFormat.Pptx);
 } finally {
     if (presentation != null) presentation.dispose();
 }

Parameters:

ParameterTypeDescription
regexjava.util.regex.PatternThe regular expression java.util.regex.Pattern to get strings to highlight.
highlightColorjava.awt.ColorThe color to highlight the text.
callbackIFindResultCallbackThe callback object for receiving search results IFindResultCallback.

highlightRegex(String regex, Color highlightColor, ITextHighlightingOptions options)

public abstract void highlightRegex(String regex, Color highlightColor, ITextHighlightingOptions options)

Highlights all matches of the regular expression with the specified color.

Parameters:

ParameterTypeDescription
regexjava.lang.StringText of regular expression to get text to highlight.
highlightColorjava.awt.ColorThe color to highlight the text.
optionsITextHighlightingOptionsHighlighting options.

replaceText(String oldText, String newText, ITextSearchOptions options, IFindResultCallback callback)

public abstract void replaceText(String oldText, String newText, ITextSearchOptions options, IFindResultCallback callback)

Replaces all occurrences of the specified text with another specified text.


The following sample code shows how to replace one specified string with another specified string.
 
 Presentation presentation = new Presentation("SomePresentation.pptx");
 try {
     TextSearchOptions textSearchOptions = new TextSearchOptions();
     textSearchOptions.setWholeWordsOnly(true);
     // Replace all separate 'the' occurrences with '***'
     ((AutoShape)presentation.getSlides().get_Item(0).getShapes().get_Item(0)).getTextFrame().replaceText("the", "***", textSearchOptions, null);
     presentation.save("SomePresentation-out2.pptx", SaveFormat.Pptx);
 } finally {
     if (presentation != null) presentation.dispose();
 }

Parameters:

ParameterTypeDescription
oldTextjava.lang.StringThe string to be replaced.
newTextjava.lang.StringThe string to replace all occurrences of oldText.
optionsITextSearchOptionsText search options ITextSearchOptions.
callbackIFindResultCallbackThe callback object for receiving search results IFindResultCallback.

replaceRegex(Pattern regex, String newText, IFindResultCallback callback)

public abstract void replaceRegex(Pattern regex, String newText, IFindResultCallback callback)

Replaces all matches of the regular expression with the specified string.


The following code sample shows how to replace text using regular expression with the specified string.
 
 Presentation presentation = new Presentation("SomePresentation.pptx");
 try {
     Pattern regex = Pattern.compile("\\b[^\\s]{5,}\\b");
     // Replace all words with 5 symbols or longer with '***'
     ((AutoShape)presentation.getSlides().get_Item(0).getShapes().get_Item(0)).getTextFrame().replaceRegex(regex, "***", null);
     presentation.save("SomePresentation-out.pptx", SaveFormat.Pptx);
 } finally {
     if (presentation != null) presentation.dispose();
 }

Parameters:

ParameterTypeDescription
regexjava.util.regex.PatternThe regular expression java.util.regex.Pattern to get strings to replace.
newTextjava.lang.StringThe string to replace all occurrences of the strings to be replaced.
callbackIFindResultCallbackThe callback object for receiving search results IFindResultCallback.