Skip to content

Commit 91384cd

Browse files
Merge pull request #442 from telerik/new-kb-update-toc-radwordsprocessing-before-docx-export-fc5dd758cc0e47c1ab2b802e55c02b62
Added new kb article update-toc-radwordsprocessing-before-docx-export
2 parents 40e55a8 + cd2d0f1 commit 91384cd

File tree

10 files changed

+80
-5
lines changed

10 files changed

+80
-5
lines changed
39.2 KB
Loading
37.8 KB
Loading
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: Updating TOC Page Numberings in Word Documents Before Exporting to DOCX Format
3+
description: Learn how to update the Table of Contents (TOC) in a Word document using RadWordsProcessing before exporting to DOCX format.
4+
type: how-to
5+
page_title: How to Update TOC Page Numberings in Word Documents Before Exporting to DOCX Format
6+
slug: update-toc-radwordsprocessing-before-docx-export
7+
tags: wordsprocessing, document, processing, toc, table, contents, update, fields, docx, export
8+
res_type: kb
9+
ticketid: 1657401
10+
---
11+
12+
## Environment
13+
14+
| Version | Product | Author |
15+
| --- | --- | ---- |
16+
| 2024.2.426| RadWordsProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|
17+
18+
## Description
19+
20+
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.
21+
22+
|Before|After|
23+
|----|----|
24+
|![TOC Before](images/toc-before.png) |![TOC After](images/toc-after.png) |
25+
26+
## Solution
27+
28+
To update the TOC in a [RadFlowDocument]({%slug radwordsprocessing-model-radflowdocument%}) before exporting it to DOCX format, follow these steps:
29+
30+
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.
31+
32+
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.
33+
34+
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.
35+
36+
```csharp
37+
FlowExtensibilityManager.NumberingFieldsProvider = new NumberingFieldsProvider();
38+
document.UpdateFields();
39+
```
40+
41+
By setting the `NumberingFieldsProvider` and then calling `RadFlowDocument.UpdateFields()`, the document will update the TOC to reflect the correct page numbering.
42+
43+
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:
44+
45+
```csharp
46+
FieldCharacter fieldCharacter = document.EnumerateChildrenOfType<FieldCharacter>().First(x=> x.FieldInfo.Field is TocField);
47+
FieldInfo fieldInfo = fieldCharacter.FieldInfo;
48+
fieldInfo.UpdateField();
49+
```
50+
51+
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.
52+
53+
## Notes
54+
55+
- 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.
56+
- 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.
57+
58+
## See Also
59+
60+
- [RadFlowDocument]({%slug radwordsprocessing-model-radflowdocument%})
61+
- [Table of Contents Field]({%slug radwordsprocessing-concepts-toc-field%})
62+
- [NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%})

libraries/radwordsprocessing/concepts/fields/numbering-fields-provider.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ This method allows you to use a custom numbering style converter.
4343

4444
The NumberingStyleConverter must implement the **INumberingStyleConverter** interface which has one method that takes a number and converts it to a string.
4545

46+
## See Also
4647

48+
- [Updating TOC Page Numberings in Word Documents Before Exporting to DOCX Format]({%slug update-toc-radwordsprocessing-before-docx-export%})
4749

4850

4951

libraries/radwordsprocessing/concepts/fields/page-field.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ position: 0
1212

1313
Inserts the current page number.
1414

15+
>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%}).
16+
1517
## Field Syntax
1618

1719
This is how the syntax of a Page field looks like:

libraries/radwordsprocessing/concepts/fields/pageref-field.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ position: 0
1212

1313
The PageRef field inserts the page number of a bookmark for a cross-reference.
1414

15+
>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%})
16+
1517
## Field Syntax
1618

1719
This is how the syntax of a PageRef field looks like:

libraries/radwordsprocessing/concepts/fields/ta-field.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The TA (Table of Authorities Entry) field defines the text and page number for a
1717
| :--- |
1818
| { **TA** [Switches ] }|
1919

20+
>information In order to update the field, you need to set the [FlowExtensibilityManager.NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}).
2021
2122
# Switches
2223

libraries/radwordsprocessing/concepts/fields/tc-field.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ position: 0
1212

1313
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.
1414

15+
>information In order to update the field, you need to set the [FlowExtensibilityManager.NumberingFieldsProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-numbering-fields-provider%}).
16+
1517
# Syntax
1618

1719
| Syntax |

libraries/radwordsprocessing/concepts/fields/toa-field.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ position: 0
1010

1111
# TOA (Table of Authorities) Field
1212

13-
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.
13+
>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.
14+
15+
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%}).
1416

1517
# Switches
1618

@@ -49,7 +51,7 @@ __Example 1__ demonstrates how you can insert a TOA field.
4951

5052
{{endregion}}
5153

52-
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%}).
54+
5355

5456
## See Also
5557

libraries/radwordsprocessing/concepts/fields/toc-field.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ position: 0
1212

1313
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.
1414

15+
>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%})
16+
17+
1518
# Syntax
1619

1720
| Syntax |
@@ -75,9 +78,8 @@ __Example 1__ demonstrates how you can insert a TOC field.
7578

7679
This makes a list of all TC fields with the 'a' identifier.
7780

78-
>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%})
79-
8081
## See Also
8182

8283
* [RadFlowDocumentEditor]({%slug radwordsprocessing-editing-radflowdocumenteditor%})
83-
* [TC field]({%slug radwordsprocessing-concepts-tc-field%}))
84+
* [TC field]({%slug radwordsprocessing-concepts-tc-field%}))
85+
* [Updating TOC Page Numberings in Word Documents Before Exporting to DOCX Format]({%slug update-toc-radwordsprocessing-before-docx-export%})

0 commit comments

Comments
 (0)