Autogenerate TOC in Word documents like html to pdf

Hi


Its possible auto generate TOC in word document like this....

                WebKitConverterSettings settings = new WebKitConverterSettings();

                settings.EnableBookmarks = true;

                settings.EnableToc = true;

                settings.Toc.Title = "Tabla de Contenido";


I like to know if same same simplicity exists for HTML to WORD conversion?


Thanks in advance



4 Replies

MR Manikandan Ravichandran Syncfusion Team January 7, 2022 12:36 PM UTC

Hi Jose,

From the given details, we have found that your requirement is to add TableOfContent (TOC) in the Word document. For this, please refer the below link to know more about TOC in DocIO.
https://help.syncfusion.com/file-formats/docio/working-with-table-of-contents

If you want to add the TOC at first of the existing Word document, you can use the below code example. 
WordDocument document = new WordDocument(inputFileName);
//Adds the paragraph into the created section
WParagraph paragraph = new WParagraph(document);
document.Sections[0].Body.ChildEntities.Insert(0, paragraph);
//Appends the TOC field with LowerHeadingLevel and UpperHeadingLevel to determines the TOC entries
paragraph.AppendTOC(1, 3);
//Updates the table of contents
document.UpdateTableOfContents();
document.Save(
"Output.docx", FormatType.Docx);
document.Close();
 

Please refer the below link to know about HTML to Word conversion and vice versa.
https://help.syncfusion.com/file-formats/docio/html

Regards,
Manikandan Ravichandran
 



JL jose luis barajas January 7, 2022 04:42 PM UTC

Hi  Manikandan Ravichandran 


I cannot run your code snippet because I get error with 

this line


document.UpdateTableOfContents(); <---- this method not exists!

I have Syncfusion.DocIO.Net.Core version 19.4.0.4




MR Manikandan Ravichandran Syncfusion Team January 10, 2022 12:20 PM UTC

Hi Jose,

To update Table of content (Enable UpdateTableOfContents API) in .net Core platform, you should use Syncfusion.DocIORenderer.Net.Core NuGet package at your end.

Please refer the below link to know about the UpdateTableOfContents.
https://help.syncfusion.com/file-formats/docio/working-with-table-of-contents#updating-table-of-contents

Regards,
Manikandan Ravichandran
 



JL jose luis barajas January 10, 2022 04:11 PM UTC

Thanks  Manikandan 


Works fine!


Loader.
Up arrow icon