From f8f946392c01f7ddf578f1217b228309b11e2b65 Mon Sep 17 00:00:00 2001 From: KB Bot Date: Wed, 17 Sep 2025 11:59:49 +0000 Subject: [PATCH 1/3] Added new kb article wordsprocessing-styling-table-of-contents-multilevel-list-numbering --- ...e-of-contents-multilevel-list-numbering.md | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 knowledge-base/wordsprocessing-styling-table-of-contents-multilevel-list-numbering.md diff --git a/knowledge-base/wordsprocessing-styling-table-of-contents-multilevel-list-numbering.md b/knowledge-base/wordsprocessing-styling-table-of-contents-multilevel-list-numbering.md new file mode 100644 index 00000000..72c776c5 --- /dev/null +++ b/knowledge-base/wordsprocessing-styling-table-of-contents-multilevel-list-numbering.md @@ -0,0 +1,137 @@ +--- +title: Styling Table of Contents with Multilevel List Numbering in Telerik WordsProcessing +description: Learn how to create and style a table of contents (TOC) with hierarchical, multilevel list numbering in Telerik WordsProcessing. +type: how-to +page_title: Applying Multilevel List Numbering to Table of Contents in Telerik WordsProcessing +meta_title: Applying Multilevel List Numbering to Table of Contents in Telerik WordsProcessing +slug: wordsprocessing-styling-table-of-contents-multilevel-list-numbering-telerik +tags: words, processing, telerik, document, processing, table, contents, toc, hierarchical, numbering, styling, multilevel, list, word, docx +res_type: kb +ticketid: 1698635 +--- + +## Environment + + + + + + + + + + + + +
Product WordsProcessing for Telerik Document Processing
Version 2025.3.806
+ +## Description + +I want to style a table of contents (TOC) in a document with hierarchical, multilevel numbering and apply specific styles to each level, such as font size, indentations, and font weight. + +This knowledge base article also answers the following questions: +- How to add hierarchical numbering to a TOC in Telerik WordsProcessing? +- How to customize TOC level styles programmatically? +- How to use ParagraphProperties and CharacterProperties to style a TOC? + +## Solution + +To achieve hierarchical, multilevel numbering in your table of contents and apply custom styles to each level, follow these steps: + +1. Set the `NumberingFieldsProvider` for the hierarchical numbering functionality. +2. Load your document using the `DocxFormatProvider`. +3. Add a table of contents field using the `RadFlowDocumentEditor`. +4. Configure hierarchical numbering by adding a list of type `NumberedHierarchical`. +5. Style each TOC level by specifying its properties using `ParagraphProperties` and `CharacterProperties`. + +### Implementation + +```csharp +using System; +using System.IO; +using System.Diagnostics; +using Telerik.Windows.Documents.Flow.Model; +using Telerik.Windows.Documents.Flow.FormatProviders.Docx; +using Telerik.Windows.Documents.Flow.Extensibility; + +// Set the NumberingFieldsProvider for hierarchical numbering support. +FlowExtensibilityManager.NumberingFieldsProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.NumberingFieldsProvider(); + +RadFlowDocument flowDocument; +DocxFormatProvider docxFormatProvider = new DocxFormatProvider(); + +// Load the document. +using (Stream input = File.OpenRead(@"C:\Users\user\Desktop\TOC.docx")) +{ + flowDocument = docxFormatProvider.Import(input, null); +} + +var editor = new RadFlowDocumentEditor(flowDocument); + +// Insert table of contents field. +FieldInfo tocFieldInfo = editor.InsertField("TOC \f a"); +tocFieldInfo.UpdateField(); + +// Create hierarchical numbering list for the TOC. +var tocList = flowDocument.Lists.Add(ListTemplateType.NumberedHierarchical); +tocList.MultilevelType = MultilevelType.Multilevel; + +// Style TOC Level 1. +var tocLevel1StyleId = BuiltInStyleNames.GetTocStyleIdByIndex(1); +flowDocument.StyleRepository.AddBuiltInStyle(tocLevel1StyleId); +var tocLevel1Style = flowDocument.StyleRepository.GetStyle(tocLevel1StyleId); +tocLevel1Style.CharacterProperties.FontSize.LocalValue = 13; +tocLevel1Style.ParagraphProperties.LeftIndent.LocalValue = 0; +tocLevel1Style.CharacterProperties.FontWeight.LocalValue = FontWeights.Bold; +tocLevel1Style.ParagraphProperties.HangingIndent.LocalValue = 35; +tocLevel1Style.ParagraphProperties.ListLevel.LocalValue = 0; +tocLevel1Style.ParagraphProperties.ListId.LocalValue = tocList.Id; + +// Style TOC Level 2. +var tocLevel2StyleId = BuiltInStyleNames.GetTocStyleIdByIndex(2); +flowDocument.StyleRepository.AddBuiltInStyle(tocLevel2StyleId); +var tocLevel2Style = flowDocument.StyleRepository.GetStyle(tocLevel2StyleId); +tocLevel2Style.ParagraphProperties.ListLevel.LocalValue = 1; +tocLevel2Style.ParagraphProperties.LeftIndent.LocalValue = 35; +tocLevel2Style.ParagraphProperties.HangingIndent.LocalValue = 35; +tocLevel2Style.CharacterProperties.FontSize.LocalValue = 13; +tocLevel2Style.ParagraphProperties.ListId.LocalValue = tocList.Id; + +// Style TOC Level 3. +var tocLevel3StyleId = BuiltInStyleNames.GetTocStyleIdByIndex(3); +flowDocument.StyleRepository.AddBuiltInStyle(tocLevel3StyleId); +var tocLevel3Style = flowDocument.StyleRepository.GetStyle(tocLevel3StyleId); +tocLevel3Style.ParagraphProperties.ListLevel.LocalValue = 2; +tocLevel3Style.ParagraphProperties.LeftIndent.LocalValue = 65; +tocLevel3Style.ParagraphProperties.HangingIndent.LocalValue = 35; +tocLevel3Style.CharacterProperties.FontSize.LocalValue = 13; +tocLevel3Style.ParagraphProperties.ListId.LocalValue = tocList.Id; + +// Export the styled document. +string docxOutputPath = "..\\..\\..\\output.docx"; +File.Delete(docxOutputPath); +using (Stream output = File.OpenWrite(docxOutputPath)) +{ + docxFormatProvider.Export(flowDocument, output, null); +} + +// Open the exported file. +var psi = new ProcessStartInfo() +{ + FileName = docxOutputPath, + UseShellExecute = true +}; +Process.Start(psi); +``` + +### Key Notes +- Use `ParagraphProperties` for indentation and hanging indentation. +- Use `CharacterProperties` for font weight and size. +- Adjust `ListLevel` and `ListId` for proper hierarchical numbering. + +## See Also + +- [WordsProcessing Overview](https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/overview) +- [Table of Contents Field](https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/fields/table-of-contents) +- [ParagraphProperties API Reference](https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/api/telerik.windows.documents.flow.model.paragraphproperties) +- [CharacterProperties API Reference](https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/api/telerik.windows.documents.flow.model.characterproperties) From 69fd27ba1ee44c8e504bd68f100cfe4824815378 Mon Sep 17 00:00:00 2001 From: "PROGRESS\\ykaraman" Date: Wed, 17 Sep 2025 15:29:38 +0300 Subject: [PATCH 2/3] Polished KB. --- ...e-of-contents-multilevel-list-numbering.md | 68 ++++++------------- .../concepts/fields/toc-field.md | 1 + 2 files changed, 23 insertions(+), 46 deletions(-) diff --git a/knowledge-base/wordsprocessing-styling-table-of-contents-multilevel-list-numbering.md b/knowledge-base/wordsprocessing-styling-table-of-contents-multilevel-list-numbering.md index 72c776c5..224b2695 100644 --- a/knowledge-base/wordsprocessing-styling-table-of-contents-multilevel-list-numbering.md +++ b/knowledge-base/wordsprocessing-styling-table-of-contents-multilevel-list-numbering.md @@ -4,45 +4,35 @@ description: Learn how to create and style a table of contents (TOC) with hierar type: how-to page_title: Applying Multilevel List Numbering to Table of Contents in Telerik WordsProcessing meta_title: Applying Multilevel List Numbering to Table of Contents in Telerik WordsProcessing -slug: wordsprocessing-styling-table-of-contents-multilevel-list-numbering-telerik +slug: wordsprocessing-styling-table-of-contents-multilevel-list-numbering tags: words, processing, telerik, document, processing, table, contents, toc, hierarchical, numbering, styling, multilevel, list, word, docx res_type: kb ticketid: 1698635 --- -## Environment - - - - - - - - - - - - -
Product WordsProcessing for Telerik Document Processing
Version 2025.3.806
+# Environment +| Version | Product | Author | +| --- | --- | ---- | +| 2025.3.806 | RadWordsProcessing |[Yoan Karamanov](https://www.telerik.com/blogs/author/yoan-karamanov)| ## Description -I want to style a table of contents (TOC) in a document with hierarchical, multilevel numbering and apply specific styles to each level, such as font size, indentations, and font weight. +This article describes how to apply multilevel list numbering and other specific styles to each level of [Table Of Contents]({%slug radwordsprocessing-concepts-toc-field%}) (TOC) in a DOCX document, such as font size, indentations, and font weight. This knowledge base article also answers the following questions: -- How to add hierarchical numbering to a TOC in Telerik WordsProcessing? +- How to add multilevel list numbering to a TOC in Telerik WordsProcessing? - How to customize TOC level styles programmatically? - How to use ParagraphProperties and CharacterProperties to style a TOC? ## Solution -To achieve hierarchical, multilevel numbering in your table of contents and apply custom styles to each level, follow these steps: +To achieve a multilevel list numbering in your [Table Of Contents]({%slug radwordsprocessing-concepts-toc-field%}) (TOC) and apply custom styles to each level, follow these steps: -1. Set the `NumberingFieldsProvider` for the hierarchical numbering functionality. -2. Load your document using the `DocxFormatProvider`. -3. Add a table of contents field using the `RadFlowDocumentEditor`. -4. Configure hierarchical numbering by adding a list of type `NumberedHierarchical`. -5. Style each TOC level by specifying its properties using `ParagraphProperties` and `CharacterProperties`. +1. Set the [`NumberingFieldsProvider`]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}) for the hierarchical numbering functionality. +2. Load your document using the [`DocxFormatProvider`]({%slug radwordsprocessing-formats-and-conversion-docx-docxformatprovider%}). +3. Add a table of contents field using the [`RadFlowDocumentEditor`]({%slug radwordsprocessing-editing-radflowdocumenteditor%}). +4. Configure hierarchical numbering by adding a list of type [`NumberedHierarchical`]({%slug radwordsprocessing-concepts-lists%}). +5. Style each TOC level by specifying its properties using [`ParagraphProperties`]({%slug radwordsprocessing-concepts-style-properties%}#style-properties-in-styles) and [`CharacterProperties`]({%slug radwordsprocessing-concepts-style-properties%}#style-properties-in-styles). ### Implementation @@ -54,14 +44,13 @@ using Telerik.Windows.Documents.Flow.Model; using Telerik.Windows.Documents.Flow.FormatProviders.Docx; using Telerik.Windows.Documents.Flow.Extensibility; -// Set the NumberingFieldsProvider for hierarchical numbering support. FlowExtensibilityManager.NumberingFieldsProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.NumberingFieldsProvider(); RadFlowDocument flowDocument; DocxFormatProvider docxFormatProvider = new DocxFormatProvider(); // Load the document. -using (Stream input = File.OpenRead(@"C:\Users\user\Desktop\TOC.docx")) +using (Stream input = File.OpenRead("input.docx")) { flowDocument = docxFormatProvider.Import(input, null); } @@ -76,7 +65,7 @@ tocFieldInfo.UpdateField(); var tocList = flowDocument.Lists.Add(ListTemplateType.NumberedHierarchical); tocList.MultilevelType = MultilevelType.Multilevel; -// Style TOC Level 1. +// Style TOC Level 1 var tocLevel1StyleId = BuiltInStyleNames.GetTocStyleIdByIndex(1); flowDocument.StyleRepository.AddBuiltInStyle(tocLevel1StyleId); var tocLevel1Style = flowDocument.StyleRepository.GetStyle(tocLevel1StyleId); @@ -87,7 +76,7 @@ tocLevel1Style.ParagraphProperties.HangingIndent.LocalValue = 35; tocLevel1Style.ParagraphProperties.ListLevel.LocalValue = 0; tocLevel1Style.ParagraphProperties.ListId.LocalValue = tocList.Id; -// Style TOC Level 2. +// Style TOC Level 2 var tocLevel2StyleId = BuiltInStyleNames.GetTocStyleIdByIndex(2); flowDocument.StyleRepository.AddBuiltInStyle(tocLevel2StyleId); var tocLevel2Style = flowDocument.StyleRepository.GetStyle(tocLevel2StyleId); @@ -97,7 +86,7 @@ tocLevel2Style.ParagraphProperties.HangingIndent.LocalValue = 35; tocLevel2Style.CharacterProperties.FontSize.LocalValue = 13; tocLevel2Style.ParagraphProperties.ListId.LocalValue = tocList.Id; -// Style TOC Level 3. +// Style TOC Level 3 var tocLevel3StyleId = BuiltInStyleNames.GetTocStyleIdByIndex(3); flowDocument.StyleRepository.AddBuiltInStyle(tocLevel3StyleId); var tocLevel3Style = flowDocument.StyleRepository.GetStyle(tocLevel3StyleId); @@ -107,31 +96,18 @@ tocLevel3Style.ParagraphProperties.HangingIndent.LocalValue = 35; tocLevel3Style.CharacterProperties.FontSize.LocalValue = 13; tocLevel3Style.ParagraphProperties.ListId.LocalValue = tocList.Id; -// Export the styled document. +// Export the styled document string docxOutputPath = "..\\..\\..\\output.docx"; File.Delete(docxOutputPath); using (Stream output = File.OpenWrite(docxOutputPath)) { docxFormatProvider.Export(flowDocument, output, null); } - -// Open the exported file. -var psi = new ProcessStartInfo() -{ - FileName = docxOutputPath, - UseShellExecute = true -}; -Process.Start(psi); ``` -### Key Notes -- Use `ParagraphProperties` for indentation and hanging indentation. -- Use `CharacterProperties` for font weight and size. -- Adjust `ListLevel` and `ListId` for proper hierarchical numbering. - ## See Also -- [WordsProcessing Overview](https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/overview) -- [Table of Contents Field](https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/fields/table-of-contents) -- [ParagraphProperties API Reference](https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/api/telerik.windows.documents.flow.model.paragraphproperties) -- [CharacterProperties API Reference](https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/api/telerik.windows.documents.flow.model.characterproperties) +* [WordsProcessing Overview]({%slug radwordsprocessing-overview%}) +* [Table of Contents Field]({%slug radwordsprocessing-concepts-toc-field%}) +* [ParagraphProperties API Reference]({%slug radwordsprocessing-concepts-style-properties%}#style-properties-in-styles) +* [CharacterProperties API Reference]({%slug radwordsprocessing-concepts-style-properties%}#style-properties-in-styles) diff --git a/libraries/radwordsprocessing/concepts/fields/toc-field.md b/libraries/radwordsprocessing/concepts/fields/toc-field.md index f3c1f89b..b1649054 100644 --- a/libraries/radwordsprocessing/concepts/fields/toc-field.md +++ b/libraries/radwordsprocessing/concepts/fields/toc-field.md @@ -84,4 +84,5 @@ This makes a list of all TC fields with the 'a' identifier. * [TC field]({%slug radwordsprocessing-concepts-tc-field%})) * [Generating a Table of Contents in a Merged Document Using RadWordsProcessing]({%slug generate-table-of-contents-radwordsprocessing%}) * [Updating TOC Page Numberings in Word Documents Before Exporting to DOCX Format]({%slug update-toc-radwordsprocessing-before-docx-export%}) +* [Styling Table of Contents with Multilevel List Numbering in Telerik WordsProcessing]({%slug wordsprocessing-styling-table-of-contents-multilevel-list-numbering%}) From 62921e334308b803b6a5c86adf90367b5ed453ce Mon Sep 17 00:00:00 2001 From: "PROGRESS\\ykaraman" Date: Thu, 18 Sep 2025 16:21:25 +0300 Subject: [PATCH 3/3] Removed link formatting. --- ...ling-table-of-contents-multilevel-list-numbering.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/knowledge-base/wordsprocessing-styling-table-of-contents-multilevel-list-numbering.md b/knowledge-base/wordsprocessing-styling-table-of-contents-multilevel-list-numbering.md index 224b2695..4d3a49f6 100644 --- a/knowledge-base/wordsprocessing-styling-table-of-contents-multilevel-list-numbering.md +++ b/knowledge-base/wordsprocessing-styling-table-of-contents-multilevel-list-numbering.md @@ -28,11 +28,11 @@ This knowledge base article also answers the following questions: To achieve a multilevel list numbering in your [Table Of Contents]({%slug radwordsprocessing-concepts-toc-field%}) (TOC) and apply custom styles to each level, follow these steps: -1. Set the [`NumberingFieldsProvider`]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}) for the hierarchical numbering functionality. -2. Load your document using the [`DocxFormatProvider`]({%slug radwordsprocessing-formats-and-conversion-docx-docxformatprovider%}). -3. Add a table of contents field using the [`RadFlowDocumentEditor`]({%slug radwordsprocessing-editing-radflowdocumenteditor%}). -4. Configure hierarchical numbering by adding a list of type [`NumberedHierarchical`]({%slug radwordsprocessing-concepts-lists%}). -5. Style each TOC level by specifying its properties using [`ParagraphProperties`]({%slug radwordsprocessing-concepts-style-properties%}#style-properties-in-styles) and [`CharacterProperties`]({%slug radwordsprocessing-concepts-style-properties%}#style-properties-in-styles). +1. Set the [NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}) for the hierarchical numbering functionality. +2. Load your document using the [DocxFormatProvider]({%slug radwordsprocessing-formats-and-conversion-docx-docxformatprovider%}). +3. Add a table of contents field using the [RadFlowDocumentEditor]({%slug radwordsprocessing-editing-radflowdocumenteditor%}). +4. Configure hierarchical numbering by adding a list of type [NumberedHierarchical]({%slug radwordsprocessing-concepts-lists%}). +5. Style each TOC level by specifying its properties using [ParagraphProperties]({%slug radwordsprocessing-concepts-style-properties%}#style-properties-in-styles) and [CharacterProperties]({%slug radwordsprocessing-concepts-style-properties%}#style-properties-in-styles). ### Implementation