TX Text Control X19 is able to generate table of contents automatically based on used styles in a document. In the ribbon tab References, the styles, that should be included in the table of contents, can be selected:
In the Table of Contents dialog, the minimum and maximum structure levels can be defined in order to add a newly generated table of contents at the current input position.
Now consider an unstructured document without used stylesheets. The user would have to create and apply styles first, before a table of contents can be generated. This sample shows how to convert an existing formatting to a style and how to apply this style to all similar paragraphs with the same layout.
The following screenshot shows a document without any stylesheets. But visually, the headings (in bold) are formatted in a different way:
The following extension method converts the formatting at the current input position into a Paragraph
╰ TXTextControl Namespace
╰ ParagraphStyle Class
The ParagraphStyle class defines a formatting style for paragraphs. and returns the newly created style name:
The next extension method applies this style to all paragraphs with the same formatting:
In the sample, a new button is added to the References tab that calls the extension methods:
Create the Table of Contents
Now, the new style can be selected as a structure level:
And after that, a table of contens can be added based on the newly created styles:
Feel free to download the sample from our GitHub repository and test this on your own.