Mmmm no purtroppo non so in anticipo questa informazione
Su una guida ho trovato il suggerimento di usare questi 3 metodi:
codice:
/* chapter14/PageXofY.java */
protected PdfTemplate total;
protected BaseFont helv;
public void onOpenDocument(PdfWriter writer, Document document) {
total = writer.getDirectContent().createTemplate(100, 100);
total.setBoundingBox(new Rectangle(-20, -20, 100, 100));
try {
helv = BaseFont.createFont(BaseFont.HELVETICA,
BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
} catch (Exception e) {
throw new ExceptionConverter(e);
}
}
public void onEndPage(PdfWriter writer, Document document) {
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
String text = "Page " + writer.getPageNumber() + " of ";
float textBase = document.bottom() - 20;
float textSize = helv.getWidthPoint(text, 12);
cb.beginText();
cb.setFontAndSize(helv, 12);
if ((writer.getPageNumber() % 2) == 1) {
cb.setTextMatrix(document.left(), textBase);
cb.showText(text);
cb.endText();
cb.addTemplate(total, document.left() + textSize, textBase);
}
else {
float adjust = helv.getWidthPoint("0", 12);
cb.setTextMatrix(
document.right() - textSize - adjust, textBase);
cb.showText(text);
cb.endText();
cb.addTemplate(total, document.right() - adjust, textBase);
}
cb.restoreState();
}
public void onCloseDocument(PdfWriter writer, Document document) {
total.beginText();
total.setFontAndSize(helv, 12);
total.setTextMatrix(0, 0);
total.showText(String.valueOf(writer.getPageNumber() - 1));
total.endText();
}
...solo che non ho capito quando usare il metodo "onEndPage" se io non so quando finisce una pagina piuttosto che un'altra......