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

Free Support Forum - aspose.com

Pages numbering into a Word document

Hello,


I want to add a footer in my Word document with the expression below :

{ IF { SECTIONPAGES } > 1 “{ PAGE }/{ SECTIONPAGES }” }

Looking at the javadoc, I don’t find any method resolving this point. Is it possible to do that ?

Thanks in advance for your answer.

Regards,

Benoît Hénaud

Hi

Thanks for your request. You should use code like the following to insert nested fields:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

// move cursor into the primary footer.

builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);

// Insert the first part of the IF field

Field field = builder.insertField("IF ");

// Move DocumentBuilder cursor to the next run after field start.

builder.moveTo(field.getStart().getNextSibling().getNextSibling());

// Insert SECTIONPAGES field.

builder.insertField("SECTIONPAGES");

// Insert operator and field code if IF field.

builder.write(" > 1 \"");

// Insert PAGE field.

builder.insertField("PAGE");

builder.write("/");

// Insert SECTIONPAGES field.

builder.insertField("SECTIONPAGES");

// Move cursor into the body.

builder.moveToDocumentEnd();

builder.write("Hello world!!!");

doc.save("C:\\Temp\\out.doc");

Hope this helps.

Best regards,

Thanks, it works well.


Regards,

Benoît Hénaud