Hello,
We are using DocIO to create a Word document (and then converting it to a PDF).
We have created a table of contents and want to set the background color, and found we can't do this directly but have to create a rectangular auto shape and set this with TextWrappingStyle to the back of the page.
This works in both Word and PDF, however...
If the table of contents is longer than one page the background is only on the first page, how do we
1. Stretch the image over multiple pages?
2. Enumerate each physical page in the table of contents section and put a shape on it?
/// <summary>
/// Adds the table of contents to the document.
/// </summary>
/// <param name="document">The document to which the table of contents should be added.</param>
private void AddTableOfContents(WordDocument document)
{
tocSection = (WSection)document.AddSection();
tocSection.PageSetup.Margins.All = 20;
tocSection.PageSetup.PageSize = new SizeF(612, 792);
IWParagraph headingParagraph = tocSection.AddParagraph();
IWTextRange heading = headingParagraph.AppendText("Table of Contents");
headingParagraph.ApplyStyle("TableOfContentsHeader");
IWParagraph paragraph = tocSection.AddParagraph();
TableOfContent toc = paragraph.AppendTOC(1, 3);
}
/// <summary>
/// Add a background to the table of contents.
/// </summary>
private void AddTableOfContentsBackground()
{
WParagraph paragraph = tocSection.Paragraphs[0];
Shape shape = paragraph.AppendShape(AutoShapeType.Rectangle, tocSection.PageSetup.PageSize.Width, tocSection.PageSetup.PageSize.Height);
shape.FillFormat.Color = Color.LightBlue;
shape.LineFormat.Line = false;
shape.HorizontalPosition = 0;
shape.VerticalPosition = 0;
shape.HorizontalAlignment = ShapeHorizontalAlignment.Left;
shape.HorizontalOrigin = HorizontalOrigin.Page;
shape.VerticalAlignment = ShapeVerticalAlignment.Top;
shape.VerticalOrigin = VerticalOrigin.Page;
shape.IsBelowText = false;
shape.WrapFormat.TextWrappingStyle = TextWrappingStyle.Behind;
}
Thanks,
Dave