Table of content

Hello,
I am trying to produce a table of content on the second page of my output document. From MS Word using F9 works ok, however I need to have it generated and displayed on opening of the document. The document is created from html in which hidden code is implemented for the option to include a toc. When this option is selected it removes the hidding code and replaces it with the InsertTableOfContent(\\o \"1-5\" \\h \\z \\u"). After saving the document to memory the document’s paragraphs are checked on the existance of heading identifiers 1 through 8, if any found then builder.doc.updatefields() and builder.doc.updatepagelayout() are called.
Regretfully without the expected result.
What am I missing or doing wrong?
Best regards,
Kees

Hello,
I have succeeded in creating the table of content and enforcing it without the use of MS Word.
However, I get space inbetween which I do not get using F9 and I like to know how I can customize the look and feel of it?
Best regards,
Kees.

Hello

Thanks for your request. Could you please attach your input and output documents here for testing. I will check the issue and provide you more information.
Best regards,

Hello,
Attatched you will find the source html (as txt file) and the output document.
The output document does contain the toc, however not as desired.
The dots inbetween should not be there, and the pagenumbers are to far to the right.
The offset on the left is also not correct. I have tried to use a table to enforce it into desired position, but then the pagenumbers were completely gone.
If you could help me out with this and some tips, I would highly appreciate it.
Best regards,
Kees

Hi

Thank you for additional information. If you would like to configure how TOC appear in the document, you can easily achieve this by editing Toc1, Toc2…TocN styles. For example, see the following code:

// Open document.
Document doc = new Document(@"Test001\mb4nzn5z.52c.doc");
// To configure how TOC look in the document, you can edit Toc1, Toc2...TocN styles.
// To demonstate the technique let's configure the first 4 levels of TOC.
Style toc1 = doc.Styles[StyleIdentifier.Toc1];
Style toc2 = doc.Styles[StyleIdentifier.Toc2];
Style toc3 = doc.Styles[StyleIdentifier.Toc3];
Style toc4 = doc.Styles[StyleIdentifier.Toc4];
Style[] tocStyles = {
    toc1,
    toc2,
    toc3,
    toc4
};
foreach(Style style in tocStyles)
{
    // increase left indent of toc items
    style.ParagraphFormat.LeftIndent += 20;
    // To incrise distance between right side and numbers we need to decrease right tabstop.
    // To achieve this we need to clear old tabstop and write new.
    // Also if you do not need tab leader (dots inbetween) you can specify TabLeader.None.
    style.ParagraphFormat.TabStops.Clear();
    style.ParagraphFormat.TabStops.Add(500, TabAlignment.Right, TabLeader.None);
}
doc.Save(@"Test001\out.doc");

Hope this could help you.
Best regards.

Hello,
Thanks very much.
Best regards,
Kees