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

Free Support Forum - aspose.com

Page number to appear other than first. ASPOSE words for JAVA

using Aspose words for java would like to know i have a document that i would like the page number to start at 3rd page. how do i do that any sample codes?

Hi Adrian,


Thanks for your inquiry. Please see attached input/output Word documents and refer to the following code example:

// This document has two sections, but no page numbers yet.
Document doc = new Document(getMyDir() + “input.docx”);

// Use document builder to create a header with a page number field for the first section.
// The page number will look like “Page V”.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToSection(0);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.write("Page ");
builder.insertField(“PAGE”, “”);

// Set first section page numbering.
Section section = doc.getSections().get(0);
section.getPageSetup().setRestartPageNumbering(true);
section.getPageSetup().setPageStartingNumber(5);
section.getPageSetup().setPageNumberStyle(NumberStyle.UPPERCASE_ROMAN);

// Create a header for the section section.
// The page number will look like " - 10 - “.
builder.moveToSection(1);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.write(” - “);
builder.insertField(“PAGE”, “”);
builder.write(” - ");

// Set second section page numbering.
section = doc.getSections().get(1);
section.getPageSetup().setPageStartingNumber(10);
section.getPageSetup().setRestartPageNumbering(true);
section.getPageSetup().setPageNumberStyle(NumberStyle.ARABIC);

doc.save(getMyDir() + “awjava-16.2.0.docx”);

Hope, this helps.

Best regards,