Insert Page Number Field at the Center of Primary Footer of Word Document using Java

HeaderFooter footer = new HeaderFooter(doc, HeaderFooterType.FOOTER_PRIMARY);
doc.getFirstSection().getHeadersFooters().add(footer);
    Paragraph footerpara = new Paragraph(doc);
    footerpara.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
    Run footerparaRun = new Run(doc);
    footerparaRun.getFont().setName("宋体");
    footerparaRun.getFont().setSize(9.0);
    footerpara.appendChild(footerparaRun);
    footerpara.appendField(FieldType.FIELD_PAGE, true);
    footerpara.appendChild(footerparaRun);
    footer.appendChild(footerpara);

image.png (92.1 KB)

@qazwsxedcrfv123,

You can insert Page field at the center of primary footer of Word document by using the following code of Aspose.Words for Java API:

Document doc = new Document("c:\\temp\\empty.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
builder.getCurrentParagraph().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.getFont().setName("宋体");
builder.getFont().setSize(9.0);
builder.insertField(FieldType.FIELD_PAGE, true);
doc.save("c:\\temp\\awjava-21.7.docx");