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

Free Support Forum - aspose.com

Adding and updating header and footer from Java

Hi All,

I need to programmatically(using java) add Type = DRAFT and Version = 0.1 to the footer of a generated word(.docx) document and then programmatically update the version and type.

Is there a way I can create a simple field called version in the header and then update it as and when required?

Cheers,

Vishal.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I think in your case you can try using bookmarks. Please see the following code:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

// Move to footer primary

builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);

builder.write("Version ");

// Insert bookmark

builder.startBookmark("Version");

builder.write("0.1");

builder.endBookmark("Version");

doc.save("C:\\Temp\\my.docx");

To update version, please try using the following code:

Document doc = new Document("C:\\Temp\\my.docx");

Bookmark version = doc.getRange().getBookmarks().get("Version");

version.setText("0.2");

doc.save("C:\\Temp\\out2.docx");

Hope this helps.

Best regards,