String textPageOfPage = String.format(pageOfPage, writer.getPageNumber());
float textBase = 18;
float textSize = helv.getWidthPoint(textPageOfPage, fontSize);
float adjust = helv.getWidthPoint("0", fontSize);
cb.addTemplate(total, document.right() - adjust, textBase);
cb.saveState();
cb.beginText();
cb.setFontAndSize(helv, fontSize);
cb.setTextMatrix(document.right() - textSize - adjust*2 , textBase);
cb.showText(textPageOfPage);