Click or drag to resize

CharacterFormat Class

Represents a set of formatting properties which shall be applied to a document text.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentFormat
    SautinSoft.DocumentCharacterFormat

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.1.24
Syntax
public sealed class CharacterFormat : Format

The CharacterFormat type exposes the following members.

Constructors
 NameDescription
Public methodCode exampleCharacterFormat Initializes a new instance of the CharacterFormat class.
Top
Properties
 NameDescription
Public propertyCode exampleAllCaps Gets or sets a value to display all characters as capital letters.
Public propertyCode exampleBackgroundColor Gets or sets the text background color. HighlightColor overrides BackgroundColor.
Public propertyCode exampleBold Gets or sets a value to display all characters as bold.
Public propertyBorder Gets or sets the border for the characters.
Public propertyDoubleStrikethrough Gets or sets a value to display all characters as double strikethrough.
Public propertyFontASCII Gets or sets a font name which shall be used to format all characters in the Unicode range (from 0 (zero) through 127).
Public propertyCode exampleFontColor Gets or sets the text color.
Public propertyFontComplexScript Gets or sets a font name which shall be used to format all characters in a complex script Unicode range.
Public propertyFontEastAsian Gets or sets a font name which shall be used to format all characters in an East Asian Unicode range.
Public propertyFontHighANSI Gets or sets a font name which shall be used to format all characters in a high ANSI Unicode range.
Public propertyCode exampleFontName When getting, returns FontASCII.
When setting, sets FontASCII, FontComplexScript, FontEastAsian and FontHighANSI to the specified value.
Public propertyHidden Gets or sets a value to format all characters as hidden.
Public propertyHighlightColor Gets or sets the text highlight (marker) color. HighlightColor overrides BackgroundColor
Public propertyCode exampleItalic Gets or sets a value to display all characters as italic.
Public propertyKerning Gets or sets the font size at which kerning starts.
Public propertyLanguage Gets or sets the language information.
Public propertyOutline Gets or sets a value to display an outline.
Public propertyPosition Gets or sets the position of text (in points) relative to the base line. A positive number raises the text, and a negative number lowers it.
Public propertyRightToLeft When true, the contents of this run shall have right-to-left reading order. Supported only in DOCX format.
Public propertyScaling Gets or sets character width scaling in percent.
Public propertyCode exampleSize Gets or sets the font size in points.
Public propertySmallCaps Gets or sets a value to display all characters as small capital letters.
Public propertySpacing Gets or sets the spacing (in points) between characters.
Public propertyStrikethrough Gets or sets a value to display all characters as strikethrough.
Public propertyCode exampleStyle Gets or sets the character style.
Public propertySubscript Gets or sets a value to display all characters as subscript.
Public propertySuperscript Gets or sets a value to display all characters as superscript.
Public propertyCode exampleUnderlineColor Gets or sets the underline color.
Public propertyCode exampleUnderlineStyle Gets or sets the type of underline.
Top
Methods
 NameDescription
Public methodClearFormatting Clears the formatting.
(Overrides FormatClearFormatting)
Public methodCode exampleClone Clones this CharacterFormat instance.
Public methodEquals Determines whether the specified object is equal to this CharacterFormat instance.
(Overrides ObjectEquals(Object))
Public methodGetHashCode Serves as the default hash function.
(Overrides ObjectGetHashCode)
Top
Example

See Developer Guide: This sample shows how to set character format

How set character formatting in C#
using SautinSoft.Document;

namespace Sample
{
    class Sample
    {

        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            CharacterFormatting();
        }

        /// <summary>
        /// This sample shows how to set character format. 
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/character-format.php
        /// </remarks>        
        public static void CharacterFormatting()
        {
            string documentPath = @"CharacterFormat.pdf";

            // Let's create a simple document.
            DocumentCore dc = new DocumentCore();

            // Add a new section.
            dc.Sections.Add(new Section(dc));

            // Add a paragraph.
            Paragraph p = new Paragraph(dc);
            p.ParagraphFormat.Alignment = HorizontalAlignment.Left;
            dc.Sections[0].Blocks.Add(p);

            // Create a formatted text (Run element) and add it into paragraph.
            Run run1 = new Run(dc, "It\'s wide formatted text.");
            run1.CharacterFormat.AllCaps = true;
            run1.CharacterFormat.BackgroundColor = Color.Pink;
            run1.CharacterFormat.FontName = "Verdana";
            run1.CharacterFormat.Size = 26f;
            run1.CharacterFormat.FontColor = new Color("#FFFFFF");

            p.Inlines.Add(run1);

            // Create another Run element (container for characters).
            Run run2 = new Run(dc, "Hi from SautinSoft!");
            run2.CharacterFormat.FontColor = Color.DarkGreen;
            run2.CharacterFormat.UnderlineStyle = UnderlineType.Dashed;
            run2.CharacterFormat.UnderlineColor = Color.Gray;

            // Add another formatted text into the paragraph.
            p.Inlines.Add(run2);

            // Add new paragraph with formatted text.
            // We are using ContentRange to insert text.
            dc.Content.Start.Insert("This is the first paragraph.\n", new CharacterFormat() { FontName = "Calibri", Size = 16.0, FontColor = Color.Orange, Bold = true });
            (dc.Sections[0].Blocks[0] as Paragraph).ParagraphFormat.Alignment = HorizontalAlignment.Center;

            dc.Content.End.Insert("Bold", new CharacterFormat() { Bold = true, FontName = "Times New Roman", Size = 11.0 });
            dc.Content.End.Insert(" Italic ", new CharacterFormat() { Italic = true, FontName = "Calibri", Size = 11.0 });
            dc.Content.End.Insert("Underline", new CharacterFormat() { UnderlineStyle = UnderlineType.Single, FontName = "Calibri", Size = 11.0 });
            dc.Content.End.Insert(" ", new CharacterFormat() { Bold = true, FontName = "Segoe UI", Size = 11.0 });
            dc.Content.End.Insert("Strikethrough", new CharacterFormat() { Strikethrough = true, FontName = "Calibri", Size = 11.0 });

            // Save our document into PDF format.
            dc.Save(documentPath, new PdfSaveOptions());

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
        }
    }
}
How set character formatting in VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        CharacterFormatting()
    End Sub
    ''' Get your free 30-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' This sample shows how to set character format. 
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/character-format.php
    ''' </remarks>
    Sub CharacterFormatting()
        Dim documentPath As String = "CharacterFormat.pdf"

        ' Let's create a simple document.
        Dim dc As New DocumentCore()

        ' Add a new section.
        dc.Sections.Add(New Section(dc))

        ' Add a paragraph.
        Dim p As New Paragraph(dc)
        p.ParagraphFormat.Alignment = HorizontalAlignment.Left
        dc.Sections(0).Blocks.Add(p)

        ' Create a formatted text (Run element) and add it into paragraph.
        Dim run1 As New Run(dc, "It's wide formatted text.")
        run1.CharacterFormat.AllCaps = True
        run1.CharacterFormat.BackgroundColor = Color.Pink
        run1.CharacterFormat.FontName = "Verdana"
        run1.CharacterFormat.Size = 26.0F
        run1.CharacterFormat.FontColor = New Color("#FFFFFF")

        p.Inlines.Add(run1)

        ' Create another Run element (container for characters).
        Dim run2 As New Run(dc, "Hi from SautinSoft!")
        run2.CharacterFormat.FontColor = Color.DarkGreen
        run2.CharacterFormat.UnderlineStyle = UnderlineType.Dashed
        run2.CharacterFormat.UnderlineColor = Color.Gray

        ' Add another formatted text into the paragraph.
        p.Inlines.Add(run2)

        ' Add new paragraph with formatted text.
        ' We are using ContentRange to insert text.
        dc.Content.Start.Insert("This is the first paragraph." & vbLf, New CharacterFormat() With {
                .FontName = "Calibri",
                .Size = 16.0,
                .FontColor = Color.Orange,
                .Bold = True
            })
        TryCast(dc.Sections(0).Blocks(0), Paragraph).ParagraphFormat.Alignment = HorizontalAlignment.Center

        dc.Content.End.Insert("Bold", New CharacterFormat() With {
                .Bold = True,
                .FontName = "Times New Roman",
                .Size = 11.0
            })
        dc.Content.End.Insert(" Italic ", New CharacterFormat() With {
                .Italic = True,
                .FontName = "Calibri",
                .Size = 11.0
            })
        dc.Content.End.Insert("Underline", New CharacterFormat() With {
                .UnderlineStyle = UnderlineType.Single,
                .FontName = "Calibri",
                .Size = 11.0
            })
        dc.Content.End.Insert(" ", New CharacterFormat() With {
                .Bold = True,
                .FontName = "Segoe UI",
                .Size = 11.0
            })
        dc.Content.End.Insert("Strikethrough", New CharacterFormat() With {
                .Strikethrough = True,
                .FontName = "Calibri",
                .Size = 11.0
            })

        ' Save our document into PDF format.
        dc.Save(documentPath, New PdfSaveOptions())

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(documentPath) With {.UseShellExecute = True})
    End Sub
End Module
See Also