diff --git a/knowledge-base/images/toc-after.png b/knowledge-base/images/toc-after.png new file mode 100644 index 00000000..12dc1257 Binary files /dev/null and b/knowledge-base/images/toc-after.png differ diff --git a/knowledge-base/images/toc-before.png b/knowledge-base/images/toc-before.png new file mode 100644 index 00000000..f6591267 Binary files /dev/null and b/knowledge-base/images/toc-before.png differ diff --git a/knowledge-base/update-toc-radwordsprocessing-before-docx-export.md b/knowledge-base/update-toc-radwordsprocessing-before-docx-export.md new file mode 100644 index 00000000..53e078a3 --- /dev/null +++ b/knowledge-base/update-toc-radwordsprocessing-before-docx-export.md @@ -0,0 +1,62 @@ +--- +title: Updating TOC Page Numberings in Word Documents Before Exporting to DOCX Format +description: Learn how to update the Table of Contents (TOC) in a Word document using RadWordsProcessing before exporting to DOCX format. +type: how-to +page_title: How to Update TOC Page Numberings in Word Documents Before Exporting to DOCX Format +slug: update-toc-radwordsprocessing-before-docx-export +tags: wordsprocessing, document, processing, toc, table, contents, update, fields, docx, export +res_type: kb +ticketid: 1657401 +--- + +## Environment + +| Version | Product | Author | +| --- | --- | ---- | +| 2024.2.426| RadWordsProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| + +## Description + +When working with Word documents that contain a [Table of Contents (TOC)]({%slug radwordsprocessing-concepts-toc-field%}), it is often necessary to update the TOC to reflect the correct page numbers before exporting the document to DOCX format. This KB article shows what steps are needed to refresh the page numbers in a document's TOC before exporting the flow document content to DOCX format. + +|Before|After| +|----|----| +|![TOC Before](images/toc-before.png) |![TOC After](images/toc-after.png) | + +## Solution + +To update the TOC in a [RadFlowDocument]({%slug radwordsprocessing-model-radflowdocument%}) before exporting it to DOCX format, follow these steps: + +1. Ensure that your document contains a [TOC field]({%slug radwordsprocessing-concepts-toc-field%}). RadWordsProcessing supports the TOC field and allows for its update before exporting the document. + +2. Before exporting the document to PDF, use the `UpdateFields()` method to update all fields, including the TOC, in the `RadFlowDocument`. This ensures that the TOC reflects the correct page numbers. + +3. To accurately update the TOC, including the correct page numbering, it's necessary to calculate the layout of the document. RadWordsProcessing provides the [NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}) for this purpose. + +```csharp +FlowExtensibilityManager.NumberingFieldsProvider = new NumberingFieldsProvider(); +document.UpdateFields(); +``` + +By setting the `NumberingFieldsProvider` and then calling `RadFlowDocument.UpdateFields()`, the document will update the TOC to reflect the correct page numbering. + +It is possible to [update just a single field](https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/concepts/fields/fields#updating-fields), not all of them: + +```csharp +FieldCharacter fieldCharacter = document.EnumerateChildrenOfType().First(x=> x.FieldInfo.Field is TocField); +FieldInfo fieldInfo = fieldCharacter.FieldInfo; +fieldInfo.UpdateField(); +``` + +4. With the TOC updated, you can now proceed to export the document to DOCX format, confident that the TOC displays the correct page references. + +## Notes + +- The `UpdateFields()` method updates all fields in the document, not just the TOC. Ensure that this behavior is acceptable for your document's needs before proceeding. +- The `NumberingFieldsProvider` plays a crucial role in ensuring that page numbers are correctly calculated and reflected in the TOC. Make sure to set it before updating the fields. + +## See Also + +- [RadFlowDocument]({%slug radwordsprocessing-model-radflowdocument%}) +- [Table of Contents Field]({%slug radwordsprocessing-concepts-toc-field%}) +- [NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}) diff --git a/libraries/radwordsprocessing/concepts/fields/numbering-fields-provider.md b/libraries/radwordsprocessing/concepts/fields/numbering-fields-provider.md index a22d3c69..be94b851 100644 --- a/libraries/radwordsprocessing/concepts/fields/numbering-fields-provider.md +++ b/libraries/radwordsprocessing/concepts/fields/numbering-fields-provider.md @@ -43,7 +43,9 @@ This method allows you to use a custom numbering style converter. The NumberingStyleConverter must implement the **INumberingStyleConverter** interface which has one method that takes a number and converts it to a string. +## See Also +- [Updating TOC Page Numberings in Word Documents Before Exporting to DOCX Format]({%slug update-toc-radwordsprocessing-before-docx-export%}) diff --git a/libraries/radwordsprocessing/concepts/fields/page-field.md b/libraries/radwordsprocessing/concepts/fields/page-field.md index a3345df8..2c94fcfc 100644 --- a/libraries/radwordsprocessing/concepts/fields/page-field.md +++ b/libraries/radwordsprocessing/concepts/fields/page-field.md @@ -12,6 +12,8 @@ position: 0 Inserts the current page number. +>information In order to update the field within the TOC field you need to set the [FlowExtensibilityManager.NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}). + ## Field Syntax This is how the syntax of a Page field looks like: diff --git a/libraries/radwordsprocessing/concepts/fields/pageref-field.md b/libraries/radwordsprocessing/concepts/fields/pageref-field.md index b6be3a1f..d802f09d 100644 --- a/libraries/radwordsprocessing/concepts/fields/pageref-field.md +++ b/libraries/radwordsprocessing/concepts/fields/pageref-field.md @@ -12,6 +12,8 @@ position: 0 The PageRef field inserts the page number of a bookmark for a cross-reference. +>information In order to update the **PageRef** fields within the TOC field you need to set the [FlowExtensibilityManager.NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}) + ## Field Syntax This is how the syntax of a PageRef field looks like: diff --git a/libraries/radwordsprocessing/concepts/fields/ta-field.md b/libraries/radwordsprocessing/concepts/fields/ta-field.md index 2d66ca01..3fb54e44 100644 --- a/libraries/radwordsprocessing/concepts/fields/ta-field.md +++ b/libraries/radwordsprocessing/concepts/fields/ta-field.md @@ -17,6 +17,7 @@ The TA (Table of Authorities Entry) field defines the text and page number for a | :--- | | { **TA** [Switches ] }| +>information In order to update the field, you need to set the [FlowExtensibilityManager.NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}). # Switches diff --git a/libraries/radwordsprocessing/concepts/fields/tc-field.md b/libraries/radwordsprocessing/concepts/fields/tc-field.md index 213656ca..010f4ff7 100644 --- a/libraries/radwordsprocessing/concepts/fields/tc-field.md +++ b/libraries/radwordsprocessing/concepts/fields/tc-field.md @@ -12,6 +12,8 @@ position: 0 The TC (Table of Contents Entry) field defines the text and page numbers for entries in a table of contents and in lists of tables, figures, and similar contents. This fields should be inserted before the text that you want to include in the contents. +>information In order to update the field, you need to set the [FlowExtensibilityManager.NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}). + # Syntax | Syntax | diff --git a/libraries/radwordsprocessing/concepts/fields/toa-field.md b/libraries/radwordsprocessing/concepts/fields/toa-field.md index bcde801b..eccd12a9 100644 --- a/libraries/radwordsprocessing/concepts/fields/toa-field.md +++ b/libraries/radwordsprocessing/concepts/fields/toa-field.md @@ -10,7 +10,9 @@ position: 0 # TOA (Table of Authorities) Field -The TOA (Table of Authorities) field creates and inserts a table of authorities. The TOA field collects entries marked by TA (Table of Authorities Entry) fields. +>information The TOA (Table of Authorities) field creates and inserts a table of authorities. The TOA field collects entries marked by TA (Table of Authorities Entry) fields. + +In order to obtain the pages of TA fields, BookmarkRangeStart, and BookmarkRangeEnd fields you need to set the [FlowExtensibilityManager.NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}). # Switches @@ -49,7 +51,7 @@ __Example 1__ demonstrates how you can insert a TOA field. {{endregion}} -In order to obtain the pages of TA fields, BookmarkRangeStart, and BookmarkRangeEnd fields you need to set the [FlowExtensibilityManager.NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}). + ## See Also diff --git a/libraries/radwordsprocessing/concepts/fields/toc-field.md b/libraries/radwordsprocessing/concepts/fields/toc-field.md index 289c976b..e31ea170 100644 --- a/libraries/radwordsprocessing/concepts/fields/toc-field.md +++ b/libraries/radwordsprocessing/concepts/fields/toc-field.md @@ -12,6 +12,9 @@ position: 0 The TOC (Table of Contents) field creates a table of contents. It is created from the heading or other styles used in the document. You can specify the items by using the TC field as well. +>information In order to update the **PageRef** fields within the TOC field you need to set the [FlowExtensibilityManager.NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}) + + # Syntax | Syntax | @@ -75,9 +78,8 @@ __Example 1__ demonstrates how you can insert a TOC field. This makes a list of all TC fields with the 'a' identifier. ->note In order to update the **PageRef** fields within the TOC field you need to set the [FlowExtensibilityManager.NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}) - ## See Also * [RadFlowDocumentEditor]({%slug radwordsprocessing-editing-radflowdocumenteditor%}) -* [TC field]({%slug radwordsprocessing-concepts-tc-field%})) \ No newline at end of file +* [TC field]({%slug radwordsprocessing-concepts-tc-field%})) +* [Updating TOC Page Numberings in Word Documents Before Exporting to DOCX Format]({%slug update-toc-radwordsprocessing-before-docx-export%}) \ No newline at end of file