/// <summary> /// Renders a Table of Contents (TOC) in front of the document. /// /// Please set the paragraphs style to "Heading{#}". /// Otherwise, it renders an empty TOC. /// </summary> private void RenderTOC() { TOC tocBuilder = new TOC(); CT_SdtBlock tableOfContents = tocBuilder.Build(); CT_P pHeader = CreateFrontHeader(); newDoc.Document.body.Items.Add(tableOfContents); newDoc.Document.body.Items.Add(pHeader); newDoc.CreateParagraph().CreateRun().AddBreak(BreakType.PAGE); newDoc.EnforceUpdateFields(); }