Repeating Headers & Footers (page numbers)

The project I am working on is dynamically generated.

For each page - I must insert a company logo (some sort of picture file) in the upper left-hand corner (above the margins) and a title in the upper right.. At bottom center I need to insert a page number and a copyright..

How do I accomplish this using a dynamically generated word doc with Aspose?

Thanks.

The first thing you need to do is to define what parts of your document are constant and put them into template.

In your case you need to make a template with header and footer. In footer you need to place a page number autotext and a copyright placeholder string, like "[copyright]" for example. This string should be substituted with actual copyright string everytime you generate the output document.

About logo insertion. If you are generating the documents for only one company and the logo is always the same then you need to put it in your template. Otherwise, you need to insert it dynamically using DocumentBuilder.InsertImage method.

That's it for the start. If you have more questions, don't hesitate to ask.

Cheers,

I would like to accomplish this without a template if possible.. IS that possible?

The logo will be flown in with an "InsertImage" - but ideally I would like to do all of it without a template. Is there a way?

Yes, with Aspose.Word you can create any kind of word documents from scratch, i.e. without using templates. The reason I've advised you to use the templates is that it is an easier and quicker way of making documents look as you want. With dynamic creation you need to make lots of experiments to make sure the document output is what you want it to be.

I will compose an example of dynamic document creation following your requirements and put it in this thread shortly.

Thanks - I would greatly appreciate it..

Here's the code snippet that does the trick:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

/*

//Specify if we want headers and footers different for first, even and odd pages.

builder.PageSetup.DifferentFirstPageHeaderFooter = true;

builder.PageSetup.OddAndEvenPagesHeaderFooter = true;

*/

builder.PageSetup.HeaderDistance = 20;

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

string imageFileName = Application.StartupPath + "\\Aspose.Word.gif";

builder.InsertImage(imageFileName, RelativeHorizontalPosition.Page, 10, RelativeVerticalPosition.Page, 10, 50, 50, WrapType.Through, WrapSide.Both, false, null);

builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;

builder.Write("ASPOSE.WORD DYNAMIC TEMPLATE");

builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;

builder.InsertField("PAGE", "");

builder.Writeln("");

builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;

builder.Writeln("(C) 2005 Aspose Pty Ltd. All rights reserved.");

doc.Save(Application.StartupPath + @"\DynamicDoc.doc");

Output results are in attachment.