We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Insert Cover Page before Table of content in word document


I want to insert cover page before TOC in word document. Also in cover page text should be vertically and horizontally center aligned. Can you please help me with the code.



Thanks for your inquiry. Please check following sample code snippet, hopefully it will help you to accomplish the task.

Document doc = new Document();
Shape text = new Shape(doc, ShapeType.TextPlainText);
text.WrapType = WrapType.None;
text.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
text.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;
text.RelativeVerticalPosition = RelativeVerticalPosition.Page;
text.VerticalAlignment = VerticalAlignment.Center;
text.Width = 100;
text.Height = 100;

text.AppendChild(new Paragraph(doc));
Paragraph para = text.FirstParagraph;
para.ParagraphFormat.Alignment = ParagraphAlignment.Center;
Run run = new Run(doc);
run.Font.Bold = true;
run.Font.Size = 14;
run.Text = "Cover Page";

Document mainDoc = new Document(@"input.docx");
DocumentBuilder builder = new DocumentBuilder(doc);            
doc.AppendDocument(mainDoc, ImportFormatMode.KeepSourceFormatting);