Hi ,
when i’m inserting appending my document with a TOC template file .
The toc inherits styling from the main Document when i append it to a main Document.
And i’m stuck with a table of contents with original sizes from the headers:
Arial Narrow , size 20 pt , bold
Arial NarrowBold , size 10 pt , bold
the styling given within the TOC and should look like :
Arial Narrow , size 10pt , bold
Arial Narrow , size 10pt
and the decoration/tableader should be none instead of dots
How can i prevent this from happening?
Has this anything to do with sections and when appending keep SourceFormatting?
I’ve included the TOC template and the current result from rendering the toc now.
Hope u can help me out .
Kind regards ,
Eric
Hi
Thanks for your inquiry. Actually TOC items should not inherit styling of Headings paragraphs. TOC items uses Toc1, Toc2…TocN styles . So 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\in.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)
{
// Change font name and size.
style.Font.Name = "Arial";
style.Font.Size = 14;
}
doc.Save(@"Test001\out.doc");
Hope this could help you.
Best regards.
Hi Andrey ,
thanks for the quick reply,
i’ve implemented the following code , but the H1 header is Styling is not applied , what can be the cause of that problem?
private Document ApplyTOCStyling(Document document)
{
Style toc1 = document.Styles[StyleIdentifier.Toc1];
Style toc2 = document.Styles[StyleIdentifier.Toc2];
Style toc3 = document.Styles[StyleIdentifier.Toc3];
toc1.Font.Bold = true;
toc1.Font.Name = "Arial Narrow";
toc1.Font.Size = 12;
toc2.Font.Bold = false;
toc2.Font.Name = "Arial Narrow";
toc2.Font.Size = 10;
return document;
}
i’ ve added the result pdf, at page 6 is the toc inserted hope you can solve this issue
Kind regards,
Eric
Hi
Thank you for additional information. But it is not quite clear for me what you mean. Could you please create a simple application, which will allow reproduce the problem? In addition, it would be useful if you attach the expected result.
Best regards,
Hi ,
I’ve created a new Simple Application ,
I already solved some problems regarding the inherriting of styling wich was cause by an older template, only thing i can’t edit in the table of contents is , the dots behind the chapter , and the size of the page number wich in the current result is very.
Hope you can help me .
Kind regards,
Eric
Hi Eric,
Thank you for additional information.
Dots between text and page number in TOC is tab leader. So if you would like to remove them, you should just modify tab leader. Please 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)
{
// 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");
The problem with page numbers seems to occur because you specified large font size for the paragraph where TOC is inserted.
Hope this could help you.
Best regards.