public static float getPageHeight(Document doc) { return doc.getPageSize().height() - doc.topMargin() - doc.bottomMargin(); }
private float getHeadTopMargin(Document doc, PdfPTable table) { return doc.getPageSize().height() - doc.topMargin() + table.getTotalHeight(); }
/** * Generates the end page for this transaction report * * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document) */ public void onEndPage(PdfWriter writer, Document document) { try { Rectangle page = document.getPageSize(); PdfPTable head = new PdfPTable(3); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); PdfPCell cell = new PdfPCell(new Phrase(sdf.format(runDate), headerFont)); cell.setBorder(Rectangle.NO_BORDER); head.addCell(cell); cell = new PdfPCell(new Phrase(title, headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); head.addCell(cell); cell = new PdfPCell(new Phrase("Page: " + new Integer(writer.getPageNumber()), headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); head.addCell(cell); head.setTotalWidth(page.width() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), page.height() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent()); } catch (Exception e) { throw new ExceptionConverter(e); } } }
head.writeSelectedRows(0, -1, document.leftMargin(), page.height() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());