Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWord
>
Tutorial
> Page numbers
The example shows you how to add page numbers to a document.
import com.independentsoft.office.word.HorizontalAlignmentType; import com.independentsoft.office.word.Paragraph; import com.independentsoft.office.word.Run; import com.independentsoft.office.word.WordDocument; import com.independentsoft.office.word.fields.Page; import com.independentsoft.office.word.fields.SimpleField; import com.independentsoft.office.word.headerFooter.Footer; public class Example { public static void main(String[] args) { try { WordDocument doc = new WordDocument(); Page pageNumber = new Page(); SimpleField simpleField = new SimpleField(pageNumber); Paragraph footerParagraph = new Paragraph(); footerParagraph.add(simpleField); footerParagraph.setHorizontalTextAlignment(HorizontalAlignmentType.CENTER); Footer footer = new Footer(); footer.add(footerParagraph); Run run1 = new Run(); run1.addText("Hello Word!"); Paragraph paragraph1 = new Paragraph(); paragraph1.add(run1); doc.getBody().add(paragraph1); doc.getBody().setFooter(footer); doc.save("c:\\test\\output.docx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*