Superscript and Subscript

Manage Super Script and Sub Script Text

You can add superscript and subscript text inside any paragraph portion. For adding Superscript or Subscript text in Aspose.Slides text frame one must use the Escapement properties of PortionFormat class.

This property returns or sets the superscript or subscript text (value from -100% (subscript) to 100% (superscript). For example :

  • Create an instance of Presentation class.
  • Obtain the reference of a slide by using its Index.
  • Add an IAutoShape of Rectangle type to the slide.
  • Access the ITextFrame associated with the IAutoShape.
  • Clear existing Paragraphs
  • Create a new paragraph object for holding superscript text and add it to the IParagraphs collection of the ITextFrame.
  • Create a new portion object
  • Set Escapement property for the portion between 0 to 100 for adding superscript. (0 mean no superscript)
  • Set some text for Portion and then add that in portion collection of paragraph.
  • Create a new paragraph object for holding subscript text and add it to the IParagraphs collection of the ITextFrame.
  • Create a new portion object
  • Set Escapement property for portion between 0 to -100 for adding superscript. (0 mean no subscript)
  • Set some text for Portion and then add that in portion collection of paragraph.
  • Save the presentation as a PPTX file.

The implementation of the above steps is given below.

using (Presentation presentation = new Presentation("test.pptx"))
{
    // Get slide
    ISlide slide = presentation.Slides[0];

    // Create text box
    IAutoShape shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 100, 100, 200, 100);
    ITextFrame textFrame = shape.TextFrame;
    textFrame.Paragraphs.Clear();

    // Create paragraph for superscript text
    IParagraph superPar = new Paragraph();

    // Create portion with usual text
    IPortion portion1 = new Portion();
    portion1.Text = "SlideTitle";
    superPar.Portions.Add(portion1);

    // Create portion with superscript text
    IPortion superPortion = new Portion();
    superPortion.PortionFormat.Escapement = 30;
    superPortion.Text = "TM";
    superPar.Portions.Add(superPortion);

    // Create paragraph for subscript text
    IParagraph paragraph2 = new Paragraph();

    // Create portion with usual text
    IPortion portion2 = new Portion();
    portion2.Text = "a";
    paragraph2.Portions.Add(portion2);

    // Create portion with subscript text
    IPortion subPortion = new Portion();
    subPortion.PortionFormat.Escapement = -25;
    subPortion.Text = "i";
    paragraph2.Portions.Add(subPortion);

    // Add paragraphs to text box
    textFrame.Paragraphs.Add(superPar);
    textFrame.Paragraphs.Add(paragraph2);

    presentation.Save("TestOut.pptx", SaveFormat.Pptx);
    System.Diagnostics.Process.Start("TestOut.pptx");
 }