Search code examples
c#wpfstringsubscript

subscript characters in String


In my WPF C# project I'm using docX library to create word documents. With this .NET library I could create String and add inside a docx file as Paragraph. My docx needs to have some subscript characters, for example:

Fb (b as subscript)

I know that there are Unicode characters and numbers for subscript, but some chars are not included. So, how can I add that subscript chars in a C# String?


Solution

  • According to a "How to write text as Subscript?" forum post webpage on the old codeplex.com, which is no longer available, you need to create a new Novacode.Formatting object. From the linked page:

    You need to create a new formatting and assign the values you want to the font.

    Dim fotext As New Novacode.Formatting

    fotext.Script = Script.subscript

    p.InsertText("Text here", False,fotext)

    p being the paragraph that you're wanting to insert text into.

    In C#, that would be something like this:

    Novacode.Formatting fotext = new Novacode.Formatting();
    fotext.Script = Script.subscript;
    p.InsertText("Text here", false, fotext);