Free Support Forum -

Urgent please..Page Number of some content in the word document

I want to construct the table of contents for a word document. So how can I dynamically determine the page number of a particular paragraph or table or content in the document.

It is not possible to determine the page number of a particular paragraph or table or content in the document with the current version of Aspose.Words. This information is not stored in the document file but is calculated by MS Word 'on the fly' during page rendering. To be able to do this in Aspose.Words we need to implement our own rendering engine, the task that is very complex and will require quite a lot of time. We are actually working on such an engine, but it is not complete yet.

But let me ask you why do you need to construct the table of contents manually in the first place. This task is usually fulfilled by insertin the TOC field to the word document. In Aspose.Words you can do this by using DocumentBuilder.InsertTableOfContents methods. Please mind, however, that to reflect the actual info the TOC inserted in Aspose.Words should be updated manually in MS Word by pressing F9.

can you give me some sample on that DocumentBuilder.InsertTableOfContents( string switches) function... what kind of string can go in there..?

Please check the example in the API reference:

Regarding format… what switch is used to set the format type to ‘Formal’ … which I could see and do in the drop down of a word document’s insert table of contents dialog box…

is there some sort of message that we can give to the user, asking him to press F9, for the table of contents to show up.. and that message should disappear once he presses it..

The easy way of doing this is to add a macro that should execute on the document startup. Just add the following procedure to your document using VBA:

Private Sub Document_Open()
End Sub

Best regards,

Finding which switch to use to implement a particular formatting is easy. Just create the TOC with desired formatting in MS Word and use ALT-F9 (to switch to field code view. You will then see all switches used in the field definition in plain text. You need just copy them to your code.

This process is described in details here: