Copy word template to new page

Hi there,
I’m using ASPOSE.WORDS to create word document.
I have a word template as attached image which have 2 “text boxes” shape at the top of the page, they are not in the header range.
When I populate data (retrieved from database) to the word as tables. I have about 10 tables, each table will be populated in 1 page.
But 2 the text boxes are only showed in the last page.
I want to keep 2 these text boxes in the all the pages.
How can I do?
Thanks,
Mike

Hi,

Thanks for your inquiry. Microsoft Word document is a flow document and it does not contain any information about its layout into lines and pages. So there is no way to determine where page starts or ends. However, you can achieve your requirement by using the utility methods available in the attached ‘PageNumberFinder’ class. Please use the following code snippet to insert shape (text box) at the top of each page.

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

PageNumberFinder pageFinder = new PageNumberFinder(doc);
// Get shape node at the top of the page
Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
for (int page = 2; page <= doc.PageCount; page++)
{
    // Returns a list of nodes that are contained anywhere on the specified page or pages which match the specified node type.
    ArrayList pageNodes = pageFinder.RetrieveAllNodesOnPages(page, page, NodeType.Paragraph);
    // Close Shape node
    Node node = shape.Clone(true);
    // insert shape at the top of page
    ((Paragraph)pageNodes[0]).AppendChild(node);
}
doc.Save(MyDir + "AsposeOut.docx");

Hope this helps you. If you still face problem, please share your template word document here for investigation purpose.

Thanks Tahir, it works!

Hi,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.