Free Support Forum - aspose.com

How to modify header/footer in Aspose.Words for Java

I've downloaded a trial version of your Java Aspose.words library for possible purchase if it meets our requirements.

Basically, I need this library to add/update Header/Footer information in .doc files. So far, it seems to handle the basic tasks but I would like to add an image to the Footer as well as page numbers (to the Footer) for each page. For example, Page x of Y (e.g. Page 2 of 100). Is this possible?

We don't have a lot of code examples yet, so you need to look at code examples for C# and essentially do the same in Java.

Here is the home page of the API Reference http://www.aspose.com/Products/Aspose.Words/Api/index.html

To quickly insert something into a header/footer you can use DocumentBuilder.MoveToHeaderFooter and then other DocumentBuilder methods as shown in this example http://www.aspose.com/Products/Aspose.Words/Api/Aspose.Words.DocumentBuilder.MoveToHeaderFooter.html

To insert a field such as "page number x of y" you can use DocumentBuilder.InsertField http://www.aspose.com/Products/Aspose.Words/Api/Aspose.Words.DocumentBuilder.InsertField.html . You can insert a field in MS Word first, see what the field code looks like and then insert same using DocumentBuilder.InsertField. Please note however, that the result of the field (the actual page number or count of pages) will not be calculated by Aspose.Words. Aspose.Words cannot evaluate expressions inside MS Word document fields. You will need to open the document in MS Word, select all and press F9 for the fields to update and show actual page numbers.

We will translate all code examples into Java soon.