How to programatically insert a table of contents

11 posts, 0 answers
  1. Axelle
    Axelle avatar
    13 posts
    Member since:
    Mar 2014

    Posted 13 Jun 2014 Link to this post

    Hi, 

    I'm programatically merging several RadDocuments to generate a report. 

    Is there a way to programatically insert a table of contents (as what is done with the menu in the examples) ? 

    Thanks, 

    Axelle
  2. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 13 Jun 2014 Link to this post

    Hello Axelle,

    You can insert a TableOfContents field using the following code snippet:

    RadDocument document = new RadDocument();
    RadDocumentEditor editor = new RadDocumentEditor(new RadDocument());
    editor.InsertField(new TableOfContentsField(), FieldDisplayMode.Result);

    Hope this answers your question.

    Regards,
    Kammen
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Axelle
    Axelle avatar
    13 posts
    Member since:
    Mar 2014

    Posted 13 Jun 2014 in reply to Kammen Link to this post

    That almost works. However I get : No table of contents entries found. 

    My guess is that it is because I use custom headers. Is there a way to specify which lists are used as table of contents entries ?
  5. Petya
    Admin
    Petya avatar
    975 posts

    Posted 17 Jun 2014 Link to this post

    Hello Axelle,

    Indeed, TOC is generated based on the paragraphs with Heading styles applied. The only way to ensure that a custom style is used in the generation of the field is to base the style on one of the headings, for example:
    StyleDefinition paragraphStyle = new StyleDefinition();
    paragraphStyle.Type = StyleType.Paragraph;
    paragraphStyle.BasedOn = this.radRichTextBox.Document.StyleRepository[RadDocumentDefaultStyles.GetHeadingStyleNameByIndex(1)];
    paragraphStyle.ParagraphProperties.Background = Colors.Red;
    paragraphStyle.DisplayName = "myStyle";
    paragraphStyle.Name = "myStyle";
     
    this.radRichTextBox.Document.StyleRepository.Add(paragraphStyle);

    You also need to set the UseParagraphsOutlineLevels property of the field to true.
    editor.InsertField(new TableOfContentsField() {  UseParagraphsOutlineLevels = true }, FieldDisplayMode.Result);

    I hope this is useful.

    Regards,
    Petya
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  6. Axelle
    Axelle avatar
    13 posts
    Member since:
    Mar 2014

    Posted 23 Jun 2014 in reply to Petya Link to this post

    No, I still get the same error (No table of content entries found).

    Is there any way to debug that ? (Or to access the various titles and their page from the document eidtor, then I can build my ToC myself).
  7. Axelle
    Axelle avatar
    13 posts
    Member since:
    Mar 2014

    Posted 23 Jun 2014 in reply to Axelle Link to this post

    Hi, I succesfully generated the table of contents, but I know have two issues :
     - The paragraph title do not contain their numbering in the table of contents
     - The page numbers are not correct (everything appears on page 1). This might be because the document is a compound of other documents. 
  8. Axelle
    Axelle avatar
    13 posts
    Member since:
    Mar 2014

    Posted 23 Jun 2014 in reply to Axelle Link to this post

    (If that plays a role, please note that the document is generated from code, and not displayed in a radrichtextbox).
  9. Axelle
    Axelle avatar
    13 posts
    Member since:
    Mar 2014

    Posted 23 Jun 2014 Link to this post

    After a few tests, the behaviour is the same if displayed in a textBox : the table of contents is ok, but the page numbers don't seem to be computed.
  10. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 26 Jun 2014 Link to this post

    Hi Axelle,

    It seems that there is a bug with the TableOfContent field. I will add it to our back log but I cannot give you any time frame when this will be fixed.

    The Telerik points are updated in your account in appreciation of your involvement.

    Regards,
    Kammen
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  11. Steve
    Steve avatar
    3 posts
    Member since:
    May 2014

    Posted 18 Dec 2015 in reply to Kammen Link to this post

    Is there an update to this?
    All of the number of the TOC contents are on Page 1. 
    I can Shift+Tab to get them to move to the next page but they default back to page 1 again the next time the document is opened.
  12. Boby
    Admin
    Boby avatar
    595 posts

    Posted 21 Dec 2015 Link to this post

    Hello Steve,

    The issue originally reported in this ticket was fixed in 2015 Q2 release (here listed as "When UpdateAllFields is called all PageReferenceFields and PageFields are updated to 1."). Could you specify your exact version, steps to reproduce the problem and the expected result? If the problem is different, I would encourage you to open separate support ticket dedicated to it.

    Regards,
    Boby
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready