// Add the RtfPageNumber to the Paragraph
par.add(new RtfPageNumber());
// Add the RtfTotalPageNumber to the Paragraph
par.add(" of ");
par.add(new RtfTotalPageNumber());
// Create an RtfHeaderFooter with the Paragraph and set it
// as a header for the document
RtfHeaderFooter header = new RtfHeaderFooter(par);
document.setHeader(header);