New to Telerik Document ProcessingStart a free 30-day trial

Resolving Distorted Font of TOC (Table of Contents) Title When Converting DOCX to PDF

Updated on Feb 24, 2026

Environment

VersionProductAuthor
2026.1.210RadWordsProcessingDesislava Yordanova
4.8.1.NET Framework

Description

When converting a DOCX file to PDF format using the WordsProcessing library, the text's font may differ from the original file for the TOC (Table of contents) title. This article explains why this is observed and how to handle this behavior.

Solution

The TOC title uses the TOC Heading style. In Word (and in RadWordsProcessing), the text Table of Contents is formatted by the built‑in style TOC Heading. If that style isn’t explicitly set (or you set it before the TOC updates), the export may fall back to defaults and you’ll see a different font in the PDF.

Once the DOCX file is imported in a RadFlowDocument using the DocxFormatProvider, there are two possible approaches to specify the font for the TOC title:

Applying a Custom Style

  1. Define a custom style for the "Table of Contents" title.
  2. Apply the custom style to the corresponding paragraph in the document.
csharp
var style = new Telerik.Windows.Documents.Flow.Model.Styles.Style(BuiltInStyleNames.TocHeadingStyleId, StyleType.Character);
style.CharacterProperties.FontFamily.LocalValue = new ThemableFontFamily("Times New Roman");
style.CharacterProperties.FontSize.LocalValue = 14;
document.StyleRepository.Add(style);

var tocTitle = document
    .EnumerateChildrenOfType<Paragraph>()
    .FirstOrDefault(p =>
        p.Inlines.OfType<Run>().Any(r =>
            (r.Text ?? string.Empty).Trim().Equals("Table of Contents", StringComparison.OrdinalIgnoreCase) ||
            (r.Text ?? string.Empty).Trim().Equals("Contents", StringComparison.OrdinalIgnoreCase)));

if (tocTitle != null)
{
    tocTitle.StyleId = BuiltInStyleNames.TocHeadingStyleId;
}

Modifying the Applied Style

  1. Get the style that is already applied to the TOC title.

  2. Adjust the imported style and apply the desired font:

csharp
var tocTitle = document
    .EnumerateChildrenOfType<Paragraph>()
    .FirstOrDefault(p =>
        p.Inlines.OfType<Run>().Any(r =>
            (r.Text ?? string.Empty).Trim().Equals("Table of Contents", StringComparison.OrdinalIgnoreCase) ||
            (r.Text ?? string.Empty).Trim().Equals("Contents", StringComparison.OrdinalIgnoreCase)));

if (tocTitle != null)
{
    var tocHeadingStyle = document.StyleRepository.GetStyle(tocTitle.StyleId);

    if (tocHeadingStyle != null)
    {
        tocHeadingStyle.CharacterProperties.FontFamily.LocalValue = new ThemableFontFamily("Times New Roman");
        tocHeadingStyle.CharacterProperties.FontWeight.LocalValue = FontWeights.Bold;
    }
}

See Also