Text Formatting

Highlight Text

New HighlightText method has been added to ITextFrame interface and TextFrame class.

It allows to highlight text part with background color using text sample, similar to Text Highlight Color tool in PowerPoint 2019.

The code snippet below shows how to use this feature:

Highlight Text using Regular Expression

New HighlightRegex method has been added to ITextFrame interface and TextFrame class.

It allows to highlight text part with background color using regex, similar to Text Highlight Color tool in PowerPoint 2019.

The code snippet below shows how to use this feature:

Align Text Paragraphs

Text formatting is one of the key elements while creating any kind of documents or presentations. We know that Aspose.Slides for .NET supports adding text to slides but in this topic, we will see that how can we control the alignment of the text paragraphs in a slide. Please follow the steps below to align text paragraphs using Aspose.Slides for .NET :

  • Create an instance of Presentation class.
  • Obtain the reference of a slide by using its Index.
  • Access the Placeholder shapes present in the slide and typecast them as a AutoShape.
  • Get the Paragraph (that needs to be aligned) from the TextFrame exposed by AutoShape.
  • Align the Paragraph. A paragraph can be aligned to Right, Left, Center & Justify.
  • Write the modified presentation as a PPTX file.

The implementation of the above steps is given below.

Set Transparency for Text

This article demonstrates how to set transparency property to any text shape using Aspose.Slides for .NET. In order to set the transparency to text. Please follow the steps below:

  • Create an instance of Presentation class.
  • Get the reference of a slide.
  • Set shadow color
  • Write the presentation as a PPTX file.

The implementation of the above steps is given below.

Manage Paragraph’s Font Properties

Presentations usually contain both text and images. The text can be formatted in a various ways, either to highlight specific sections and words, or to conform with corporate styles. Text formatting helps users vary the look and feel of the presentation content. This article shows how to use Aspose.Slides for .NET to configure the font properties of paragraphs of text on slides. To manage font properties of a paragraph using Aspose.Slides for .NET :

  1. Create an instance of the Presentation class.
  2. Obtain a slide’s reference by using its index.
  3. Access the Placeholder shapes in the slide and typecast them to AutoShape.
  4. Get the Paragraph from the TextFrame exposed by AutoShape.
  5. Justify the paragraph.
  6. Access a Paragraph’s text Portion.
  7. Define the font using FontData and set the Font of the text Portion accordingly.
    1. Set the font to bold.
    2. Set the font to italic.
  8. Set the font color using the FillFormat exposed by the Portion object.
  9. Write the modified presentation to a PPTX file.

The implementation of the above steps is given below. It takes an unadorned presentation and formats the fonts on one of the slides.

Manage Font Family of Text

As mentioned in Managing Font Related Properties a Portion is used to hold text with similar formatting style in a paragraph. This article shows how to use Aspose.Slides for .NET to create a textbox with some text and then define a particular font, and various other properties of the font family category. To create a textbox and set font properties of the text in it:

  • Create an instance of the Presentation class.
  • Obtain the reference of a slide by using its index.
  • Add an AutoShape of the type Rectangle to the slide.
  • Remove the fill style associated with the AutoShape.
  • Access the AutoShape’s TextFrame.
  • Add some text to the TextFrame.
  • Access the Portion object associated with the TextFrame.
  • Define the font to be used for the Portion.
  • Set other font properties like bold, italic, underline, color and height using the relevant properties as exposed by the Portion object.
  • Write the modified presentation as a PPTX file.

The implementation of the above steps is given below.

Set Text Rotation

Aspose.Slides for .NET allows developers to rotate the text. Text could be set to appear as Horizontal, Vertical, Vertical270, WordArtVertical, EastAsianVertical, MongolianVertical or WordArtVerticalRightToLeft. To rotate the text of any TextFrame, please follow the steps below:

  • Create an instance of Presentation class.
  • Access the first slide.
  • Add any Shape to the slide.
  • Access the TextFrame.
  • Rotate the text.
  • Save file to disk.

Set Custom Rotation Angle for TextFrame

Aspose.Slides for .NET now supports, Setting custom rotation angle for textframe. In this topic, we will see with example how to set the RotationAngle property in Aspose.Slides. The new property RotationAngle has been added to IChartTextBlockFormat and ITextFrameFormat interfaces, allows to set the custom rotation angle for textframe. In order to set the RotationAngle property, Please follow the steps below:

  • Create an instance of Presentation class.
  • Add a chart on slide.
  • Set RotationAngle property.
  • Write the presentation as a PPTX file.

In the example given below, we set the RotationAngle property.

Line Spacing of Paragraph

Aspose.Slides for .NET lets developers to set the properties of ParagraphFormat to deal with line spacing of the paragraph. The properties SpaceAfter, SpaceBefore and SpaceWithin could be set for different line spacing. This article explains how to set these properties of ParagraphFormat. Aspose.Slides for .NET provides a simple API for setting properties of ParagraphFormat:

  • Load a presentation with an AutoShape having some text in it.
  • Obtain a slide’s reference by its index.
  • Access the TextFrame.
  • Access the Paragraph.
  • Set properties of Paragraph.
  • Save the presentation to disk.

Set the AutofitType Property for TextFrame

In this topic, we will explore the different formatting properties of text frame. This article covers how to Set the AutofitType property of text frame, anchor of text and rotating the text in presentation. Aspose.Slides for .NET allows developers to set AutofitType property of any text frame. AutofitType could be set to Normal or Shape. If set to Normal then shape will remain the same whereas the text will be adjusted without causing the shape to change itself whereas If AutofitType is set to shape, then shape will be modified such that only required text is contained in it. To set the AutofitType property of a text frame, please follow the steps below:

  • Create an instance of Presentation class.
  • Access the first slide.
  • Add any shape to the slide.
  • Access the TextFrame.
  • Set the AutofitType of the TextFrame.
  • Save file to disk.

Set Anchor of TextFrame

Aspose.Slides for .NET allows developers to Anchor of any TextFrame. TextAnchorType specifies that where is that text placed in the shape. TextAnchorType could be set to Top, Center, Bottom, Justified or Distributed. To set Anchor of any TextFrame, please follow the steps below:

  • Create an instance of Presentation class.
  • Access the first slide.
  • Add any shape to the slide.
  • Access the TextFrame.
  • Set TextAnchorType of the TextFrame.
  • Save file to disk.

Set Text Tabulation

  • EffectiveTabs.ExplicitTabCount (2 in our case) property is equal to Tabs.Count.
  • EffectiveTabs collection includes all tabs (from Tabs collection and default tabs)
  • EffectiveTabs.ExplicitTabCount (2 in our case) property is equal to Tabs.Count.
  • EffectiveTabs.DefaultTabSize (294) property shows distance between default tabs (3 and 4 in our example).
  • EffectiveTabs.GetTabByIndex(index) with index = 0 will return first explicit tab (Position = 731), index = 1 - second tab (Position = 1241). If you try to get next tab with index = 2 it will return first default tab (Position = 1470) and etc.
  • EffectiveTabs.GetTabAfterPosition(pos) used for getting next tabulation after some text. For example you have text: “Helloworld!”. To render such text you should know where to start draw “world!”. At first, you should calculate length of “Hello” in pixels and call GetTabAfterPosition with this value. You will get next tab position to draw “world!”.