Text scrolling down when generating TOC(TableOfContentsField) in RadDocument using RadDocumentEditor

1 Answer 27 Views
Top achievements
Rank 1
Pablo asked on 24 Jun 2022, 02:35 AM

Hello everyone. I have this problem when generating a table of contents. It is happening to me that when the document is exported to Word, for some reason (or if it is the correct behavior) the text is scrolling down on the next page. What I want to achieve is that the TOC can be generated if scrolling down occurs or, failing that, eliminate the space between the phrase "GENERAL CHARACTERISTICS" and the top of the header of that page. The document is already created and is imported into the application. I'm using an example that I found in the forum (I don't remember the name of the person, credits to him) and I'm adapting it to what I need

I have been researching the way to do it and I think with "Multi-Range Selection"
(https://docs.telerik.com/devtools/wpf/controls/radrichtextbox/features/selection?&_ga=2.154034736.904289798.1655964538-1262658420.1654800489#members-of-documentselection) between the phrase and the last element of the TOC would work but I haven't managed to capture the last element of the TOC, so I'm stuck with that part. Any idea or way I can take to eliminate that generated (dynamic) space between the phrase the following sheet and the header of that page.

Attached functional solution for testing and images.

Thank you very much

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 27 Jun 2022, 03:18 PM

Hello Pablo,

The text goes on the next page because there are empty paragraphs in the original document that are pushed down after inserting the TOC. You can remove them and add a page break after the TOC to ensure that the text starts on a new page:


// Move to the next paragraph and check whether it has any content
var currentParagraph = documentEditor.Document.CaretPosition.GetCurrentParagraph();
while (currentParagraph.IsEmpty)
    // Delete the current empty paragraph
    // Get the next paragraph
    currentParagraph = documentEditor.Document.CaretPosition.GetCurrentParagraph();


documentEditor.InsertField(field, FieldDisplayMode.DisplayName);
// Insert a break after the field

Hope this is helpful.

Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Top achievements
Rank 1
commented on 28 Jun 2022, 06:29 PM

Thank you very much Tanya. that works perfectly. Now a question: is there a way to do that same functionality but with RadFlowDocument and RadFlowDocumentEditor ?

Or is there a way to port the functionality contained in the RadDocument DLLs to a NetCore 5.0/6.0 project? Thank you very much

Telerik team
commented on 01 Jul 2022, 09:35 AM

Hi Pablo,

You can use the RadDocument class in a .NET Core application. However, to run it, you should also have installed the Windows Compatibility Pack.

If this is not an option for you, you can also port the code to use the API of WordsProcessing and its RadFlowDocument. The API is pretty similar to the one of RadDocument and you can refer to our documentation for the library for more details about the different functionalities. Something you should have in mind is that the TOC field is not completely supported. You can insert such a field but it needs to be updated by the application that will open the document.

Hope this information is helpful.

Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question