How to update TOC(Table of content)

0
Dhaneesh posted this 19 June 2020

Hi,

I want to update TOC (Table of content ) dynamically .How to refresh the TOC

some one can help me with code sample .

Last edited 19 June 2020

2 Posts
2 Points
3 Comments
Order By: Standard | Newest | Votes
0
jles posted this 13 July 2020

Hi Dhaneesh,

Basically, what you need to do is: 1. Load the docx document using the Document.Load static method. 2. Save the loaded document using the Document.Save method.

See the snippet below:

Document document;
using (FileStream fileStream = File.Open(@"c:\InputWordDocument.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
    document = Document.Load(fileStream);
}

// The Document.Save method also rebuilds TOC. You can use the Stream-based overload of this method.
document.Save(@"c:\ResultWordDocument.docx");

I hope this helps.

Regards, Jure

Last edited 15 September 2020

154 Posts
294 Points
0
Dhaneesh posted this 22 June 2020

Hi,

thank you for your response

I was trying on word (.docx) where we have table of contents it should be dynamically update based on the visibility of contents(table content -table header style -heading 1).

Can you help me how DOM APIs to rebuild the TOC with code in c#.(Update dynamic fields, such as Table Of Contents (TOC).

(Note:C# programmatically)

Regards Dhaneesh

Last edited 23 June 2020

2 Posts
2 Points
0
jles posted this 19 June 2020

Hi,

Thank you for your question. TOC is always rebuilt when generating PDF files via DocumentGenerator. If your output is Word (.docx) format, then TOC is not automatically rebuilt and you need to use the DOM APIs to rebuild the TOC. Could you please give me more details about what you are trying to achieve?

Best regards, Jure

154 Posts
294 Points

Our 226160 members have posted 342 times in 101 discussions