TOC (Table of contents) field


Does Apose Words have the capability to remove TOC line items dynamically?

For example, if a section in a word template were to be removed dynamically using Apose could its corresponding TOC line item be removed along with it?




TOC is actually just a short field in a Word document. It is rendered as a list of headings by MS Word. When one of the document content items is removed the TOC will remove the corresponding heading. However, TOC field should be updated for this to happen. Microsoft Word does not automatically update TOC field, you need to update it manually by pressing F9.

Hope this answers your question.


That was what I had suspected and known, so I guess it begs the question:

Can Aspose Words simulate this TOC update dynamically?

I know from experience that Apose PDF picks up on the TOC field in a word document and then updates the page numbers dynamically so that the hyperlinks in the TOC have current page numbers. Can this feature not be extended to update the whole TOC field.


Aspose.Words cannot update TOC yet mainly because we need a page layout engine to be able to calculates page numbers for TOC. We are working on page layout engine and after it will be implemented we will probably be able to do updates like this dynamically. The timeline for this issue is 4-5 months approximately.

Aspose.Pdf is essentially a layout and rendering formatting library due to specific nature of PDF format, that's why they already have the ability to calculate page numbers.


Are you aware of any work arounds for this? Eg a macro in the
template that could update the TOC as soon as a word doc is opened?



That looks like a good idea. I will check if such a macro can be written.


That looks pretty easy. Just add the following procedure to your document VBA code:

Private Sub Document_Open()
End Sub


Any updates on the ability to do this from within Aspose.Word?

We're currently using the above macro to do this, but it would be very nice if we didn't have to.




Just added this to our new FAQ thread. Thanks.