Articles in this section
Category / Section

How to resize list character in a Word document?

2 mins read

Syncfusion Essential DocIO is a .NET Core Word library used to create, read, and edit Word documents programmatically without Microsoft Word or Interop dependencies. Using this library, you can resize list characters in a Word document in C#.

Steps to resize list characters in a Word document:

  1. Create a new C# .NET Core console application project. Create .NET Core console application in Visual Studio in ASP.NET Core Word
  2. Install the Syncfusion.DocIO.Net.Core NuGet package to reference your .NET Core applications from NuGet.org.Add DocIO.Net.Core NuGet packages of ASP.NET Core Word
  3. Include the following namespace in the Program.cs file.

C#

using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
  1. Use the following code example to resize list characters in a Word document.

C#

using (FileStream fileStream = new FileStream(Path.GetFullPath(@"../../../Template.docx"), FileMode.Open, FileAccess.ReadWrite))
{
    //Open the template document.
    using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic))
    {
        //Iterate through each section of the Word document.
        foreach (WSection section in document.Sections)
        {
            //Access the body of section where all the contents in document are apart.
            WTextBody sectionBody = section.Body;
            IterateTextBody(sectionBody);
            IterateHeaderFooter(section);
        }
        //Create file stream.
        using (FileStream outputStream = new FileStream(Path.GetFullPath(@"../../../Result.docx"), FileMode.Create, FileAccess.ReadWrite))
        {
            //Save the Word document to file stream.
            document.Save(outputStream, FormatType.Docx);
        }
    }
}
  1. Use the following helper methods to resize list characters in a Word document.

C#

/// <summary>
/// Iterate through the headers and footers.
/// </summary>
 private static void IterateHeaderFooter(WSection section)
{
    WHeadersFooters headersFooters = section.HeadersFooters;
    //Iterate through the textBody of all Headers and Footers.
    IterateTextBody(headersFooters.OddHeader);
    IterateTextBody(headersFooters.OddFooter);
    IterateTextBody(headersFooters.EvenHeader);
    IterateTextBody(headersFooters.EvenFooter);
    IterateTextBody(headersFooters.FirstPageHeader);
    IterateTextBody(headersFooters.FirstPageFooter);
}
 
/// <summary>
/// Iterate through document textbody.
/// </summary>
private static void IterateTextBody(WTextBody textBody)
{
    //Iterate through each of the child items of WTextBody
    for (int i = 0; i < textBody.ChildEntities.Count; i++)
    {
        //Access the body items (should be either paragraph, table or block content control) as IEntity
        IEntity bodyItemEntity = textBody.ChildEntities[i];
        //Decide the element type by using the EntityType
        switch (bodyItemEntity.EntityType)
        {
            case EntityType.Paragraph:
                WParagraph paragraph = bodyItemEntity as WParagraph;
                //Change the list character size.
                if (paragraph.ListFormat != null && paragraph.ListFormat.CurrentListLevel != null)
                            paragraph.ListFormat.CurrentListLevel.CharacterFormat.FontSize = 25;
                break;
            case EntityType.Table:
                //Iterate through table.
                IterateTable(bodyItemEntity as WTable);
                break;
            case EntityType.BlockContentControl:
                BlockContentControl blockContentControl = bodyItemEntity as BlockContentControl;
                //Iterate to the body items of the Block Content Control.
                IterateTextBody(blockContentControl.TextBody);
                break;
        }
    } 
}
/// <summary>
/// Iterate through document table.
/// </summary>
private static void IterateTable(WTable table)
{
    //Iterate the row collection in a table
    foreach (WTableRow row in table.Rows)
    {
        //Iterate the cell collection in a table row.
        foreach (WTableCell cell in row.Cells)
        {
            IterateTextBody(cell);
        }
    }
}

A complete working sample to resize list characters in a Word document in C# can be downloaded from GitHub.

By executing the program, you will get the Output document as follows.

Output document generated in ASP.NET Core Word 

Take a moment to peruse the documentation, where you can find basic Word document processing options along with the features like mail mergemerge and split documents, find and replace text in the Word document, protect the Word documents, and most importantly, the PDF and Image conversions with code examples.

Explore more about the rich set of Syncfusion Word Framework features.

See Also:

How to create the deep level numbering( 1.1-1.2.1-1.2.2 etc.) using DocIO?

How to change the character/symbol used for bullet points in Word document?

How to find list of used fonts in the Word document

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied