Table of Contents loses style after updating

Hi,

I'm following the tutorial to add a table of contents to my document, but when I call document.UpdateTableOfContents(), it gets updated but loses all formatting. Am I missing something?


var partoc = section.AddParagraph();
partoc.ParagraphFormat.SpaceAfterAuto = true;


Style stylep = (WParagraphStyle)document.AddParagraphStyle("TOCStyle");

stylep.CharacterFormat.Bold = true;
stylep.CharacterFormat.FontName = "Helvetica";
stylep.CharacterFormat.FontSize = 10;


TableOfContent toc = partoc.AppendTOC(1, 3);

toc.UseHeadingStyles = true;
toc.IncludePageNumbers = true;
toc.RightAlignPageNumbers = true;
toc.UseHyperlinks = true;
toc.SetTOCLevelStyle(1, "TOCStyle");
toc.SetTOCLevelStyle(2, "TOCStyle");

partoc.ApplyStyle("TOCStyle");

document.UpdateTableOfContents()

1 Reply

DS Dharanya Sakthivel Syncfusion Team October 19, 2024 07:24 AM UTC

Hi Daniel,

Regarding "When I call document.UpdateTableOfContents(), it gets updated but loses all formatting. Am I missing something?"
Based on the details you provided, it seems that the specified style is not being applied to the TOC entries after calling UpdateTableOfContents(). The style you defined is being applied to the headings themselves, but it does not carry over to the TOC entries when the table of contents is updated.

To address this, please refer to the documentation and GitHub samples that demonstrate how to create a table of contents using user-defined styles. This approach will help ensure that your custom styles are correctly applied to the TOC headings, even after updating it.

If you are still having concerns, kindly share the following details to help us understand the issue better:

  1. The complete code snippet.

  2. A screenshot of the issue.

  3. The result document.

This information will help us in providing a more accurate solution.


Regards,
Dharanya.


Loader.
Up arrow icon