How to format table of content using Aspose.Words for .NET

Hi ,

I am merging a number of documents of different types , and i am creating a numbered table of contents. And this works fine. However now i need to place the table of contents in the first page but in the middle of the page. I have attempted to set the margin top properties and also paragraph .SpaceBefore property but the table of contents either stays in the default position , or my whole document takes on the Margin top property.

Is it possible to set the Top property or absolute position the Table of Contents in an Aspose PDF document ? Thanks ,

Ali

Hi Ali,

Thanks for your query. Please use the following code snippet to add space before in TOC.

Document doc = new Document(MyDir + "in.docx");

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 toc5 = doc.Styles[StyleIdentifier.Toc5];

Style[] tocStyles = { toc1, toc2, toc3, toc4, toc5 };

foreach (Style style in tocStyles)

{

// change spacing.

style.ParagraphFormat.SpaceAfterAuto = false;

style.ParagraphFormat.SpaceBefore = 10;

}

doc.Save(MyDir + "AsposeOut.docx");

It would be great if you please share some more information about your following question.

Is it possible to set the Top property or absolute position the Table of Contents in an Aspose PDF document ?