This is a migrated thread and some comments may be shown as answers.

Setting heading levels to multi-layered decimal and TOC styling

5 Answers 285 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Joonatan
Top achievements
Rank 1
Joonatan asked on 29 Sep 2014, 10:14 AM
I am generating a report in docx through our application using telerik Document processing. So far I've been able to add the correct content, but I've encountered some styling issues regarding the heading levels. I've successfully changed the styling for all the levels to decimal instead of aplhabetical, lower roman etc... but this results in each heading level restarting their heading display as simply "1" instead of for example the first level 2 header being "1.1". Could you please help me to obtain this formatting? 

The current way I have set the heading numbering to decimal is:

ListStyle newListStyle = DefaultListStyles.Numbered;
 
 DocumentList documentList = new DocumentList(newListStyle, Document);
 
 for(int i=0;i<maxTOClevel;i++)
 {
     documentList.Style.Levels[i].Indent = 0;
     documentList.Style.Levels[i].HangingIndent = 0;
     documentList.Style.Levels[i].NumberingFormat = ListNumberingFormat.Decimal;
 
 }


Regarding the table of contents formatting, I cannot find where to specify that the header numbers should be visible in the table of contents, nor where to change the line decoration between title and page number to a solid line instead of a dotted one. Perhaps they are both located in the same styling object?

I've tried setting the underline decoration to a solid line via:
StyleDefinition toc1Style = Document.StyleRepository[RadDocumentDefaultStyles.GetTocStyleNameByIndex(1)];
toc1Style.SpanProperties.UnderlineDecoration = UnderlineTypes.Line;

but this simply adds a line under the entire row, instead of changing the existing dotted line into a solid one. Any help regarding these formatting questions would be greatly appreciated.

5 Answers, 1 is accepted

Sort by
0
C
Top achievements
Rank 1
answered on 01 Oct 2014, 10:20 PM
See this thread for TOC and TOC styling in C# code without creating a RichTextBox control.

http://www.telerik.com/forums/raddocument---programmatically-create-word-document-with-table-of-contents-sections-and-subsections
0
Petya
Telerik team
answered on 02 Oct 2014, 08:29 AM
Hello Joonatan,

I'm having a hard time understanding your first question. The code you sent us shows how you are creating a document list, but it does not show how are you applying it to paragraphs in your document, so it's hard to say what exactly causes the inconsistent behavior. Could you please share those details with us?

As to the table of contents styling, at this point the tab stop leader cannot be modified when you are creating a TOC field from code, only when adding it through the dialog in the control's UI. We are considering  exposing such option for one of our next releases and you can track our progress in the Ideas & Feedback Portal.

As to the page numbers, by default creating table of contents should include the pages in the field. Please provide more details on the issue that you are experiencing.

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.
 
0
Joonatan
Top achievements
Rank 1
answered on 02 Oct 2014, 08:55 AM
Thank you for your reply Petya.

Regarding the first question, I managed to achieve what I wanted by setting my ListStyle for the document to:

ListStyle newListStyle = DefaultListStyles.NumberedHierarchical;

So this is no longer an issue.

However, regarding what you said about the tab stop leader not being able to me modified via code, does this mean I cannot change the dotted line between headers and their page numbers in the ToC to dashed instead of dotted without using the control's UI?

As for the heading numbers in the ToC, I create my ToC in the following way:

TableOfContentsField field = new TableOfContentsField();
            RadDocumentEditor documentEditor = new RadDocumentEditor(Document);
 
            Paragraph tempParagraph = new Paragraph();
            tempParagraph.Inlines.Add(new Span("Table of contents"){Style = _headerOnWhiteStyle});
            _tocSection.Blocks.Add(tempParagraph);
            //Go to the section where the TOC field is to be inserted
            documentEditor.Document.CaretPosition.MoveToEndOfDocumentElement(_tocSection); //tocSection was defined previously
            documentEditor.InsertField(field, FieldDisplayMode.Result);
            documentEditor.UpdateAllFields(FieldDisplayMode.Result); //compute page numbers for TOC

I add header paragraphs in the following way (for example):

Section contentSection = new Section();
 
contentSection.Blocks.Add(CreateHeadingParagraph(_documentList, "This is heading 2", 2);

where:

private Paragraph CreateHeadingParagraph(DocumentList documentList, string headingText, int headingLevel)
        {
            Paragraph headingParagraph = new Paragraph() { StyleName =             RadDocumentDefaultStyles.GetHeadingStyleNameByIndex(headingLevel) };
            headingParagraph.Inlines.Add(new Span(headingText));
 
            if(headingLevel >= 1 && headingLevel <= MAXHEADINGLEVEL)
            {
                headingParagraph.ListId = documentList.ID; //add it to the doc list
                headingParagraph.ListLevel = headingLevel - 1;
            }
            return headingParagraph;
        }

and the document list is defined in the following way:

ListStyle newListStyle = DefaultListStyles.NumberedHierarchical;
_documentList = new DocumentList(newListStyle, Document);

and Document is the RadDocument I am currently working with.

However, in the ToC all I get are the heading names with a dotted line leading to their page numbers, no heading numbers. So what I can see is:

Heading1............................... 1
   Heading2 ............................2

But what I would like to have is:

1 Heading1.............................1
   1.2 Heading2.......................2

Also, headings with levels larger than my MAXHEADINGLEVEL are being included in the table of contents, so I assume I am not excluding what should be in the ToC correctly?

I really appreciate your help, please let me know if you require more information regarding the matter. 
0
Accepted
Petya
Telerik team
answered on 06 Oct 2014, 02:48 PM
Hi,

Here is the public item where you can track the team's progress on allowing to modify the tabstop leader programmatically.

As to placing the entries from the TableOfContents field in a list, the best approach that you could adopt at this point is to modify the styles that are applied to those entries and include them in a list. Here is how to do that for the toc1 and toc2 styles in the currently shown in RadRichTextBox document:
DocumentList list = new DocumentList(DefaultListStyles.Numbered, this.radRichTextBox.Document);
 
var toc1 = this.radRichTextBox.Document.StyleRepository[RadDocumentDefaultStyles.GetTocStyleNameByIndex(1)];
toc1.ParagraphStyle.ListLevel = 0;
toc1.ParagraphStyle.ListId = list.ID;
 
var toc2 = this.radRichTextBox.Document.StyleRepository[RadDocumentDefaultStyles.GetTocStyleNameByIndex(2)];
toc2.ParagraphStyle.ListLevel = 1;
toc2.ParagraphStyle.ListId = list.ID;

Regards,
Petya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Joonatan
Top achievements
Rank 1
answered on 09 Oct 2014, 08:03 AM
I figured I would summarize the answers I've gotten from Telerik to my questions in this post.

1. To get heading numbering style of the type 

1. Heading 1
    1.1 Heading 2
    1.2. Another heading 2

use

ListStyle newListStyle = DefaultListStyles.NumberedHierarchical;

 When defining your list style. Then to get the numbering in the ToC, as Petya said modify the ToC styles to be included in the same list with their respective levels:

DocumentList list = new DocumentList(DefaultListStyles.Numbered, this.radRichTextBox.Document);
  
var toc1 = this.radRichTextBox.Document.StyleRepository[RadDocumentDefaultStyles.GetTocStyleNameByIndex(1)];
toc1.ParagraphStyle.ListLevel = 0;
toc1.ParagraphStyle.ListId = list.ID;
  
var toc2 = this.radRichTextBox.Document.StyleRepository[RadDocumentDefaultStyles.GetTocStyleNameByIndex(2)];
toc2.ParagraphStyle.ListLevel = 1;
toc2.ParagraphStyle.ListId = list.ID;

However this approach is more of a work-around and results in the alignment of your ToC entries to be incorrect, but Telerik is looking into this. 

To include only certain levels in your ToC, set the following properties in your ToC field:

TableOfContentsField field = new TableOfContentsField();
            field.OutlineLevelsInRange = "1-3"; //this is for levels 1-3
            field.UseOutlineLevelsInRange = true;

Regarding how to change the lines leading from the headings to the page numbers, this is not possible at the time.

Thank you Petya and the Telerik team for your help!







ListStyle newListStyle = DefaultListStyles.NumberedHierarchical;
Tags
RichTextBox
Asked by
Joonatan
Top achievements
Rank 1
Answers by
C
Top achievements
Rank 1
Petya
Telerik team
Joonatan
Top achievements
Rank 1
Share this question
or