class MyFooter extends PdfPageEventHelper { Font ffont = new Font(Font.FontFamily.UNDEFINED, 5, Font.ITALIC); public void onEndPage(PdfWriter writer, Document document) { PdfContentByte cb = writer.getDirectContent(); Phrase header = new Phrase("this is a header", ffont); Phrase footer = new Phrase("this is a footer", ffont); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, header, (document.right() - document.left()) / 2 + document.leftMargin(), document.top() + 10, 0); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer, (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() - 10, 0); } }
public static float getPageWidth(Document doc) { return doc.getPageSize().width() - doc.leftMargin() - doc.rightMargin(); }
document.leftMargin() - 1, document.top() + 30, 0);
public class MyPageEventListener extends PdfPageEventHelper { . . . @Override public void onEndPage(PdfWriter writer, Document document) { //code skeleton to write page header PdfPTable tbl = new PdfPTable(3); tbl.addCell("1st cell"); tbl.addCell("2nd cell"); tbl.addCell("3rd cell"); float x = document.leftMargin(); float hei = getMyHeaderHeight(); //custom method that return header's height //align bottom between page edge and page margin float y = document.top() + hei; //write the table tbl.writeSelectedRows(0, -1, x, y, writer.getDirectContent()); } }
float x = document.leftMargin(); float hei = header.getTotalHeight(); //altezza dell'intestazione
title.addCell(new Phrase(descriptionRow, Style.FRONTPAGE_FONT_2)); title.addCell(new Phrase(dateRow, Style.FRONTPAGE_FONT_3)); title.setTotalWidth(pageSize.getWidth() - frontPageDocument.leftMargin() - frontPageDocument.rightMargin()); title.writeSelectedRows(0, -1, frontPageDocument.leftMargin(), pageSize.getHeight() - logoImage.getHeight() - 150, frontPageWriter.getDirectContent());
/** * 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); } } }
Style.FRONTPAGE_FONT_3)); title.addCell(new Phrase(dateRow, Style.FRONTPAGE_FONT_3)); title.setTotalWidth(pageSize.getWidth() - frontPageDocument.leftMargin() - frontPageDocument.rightMargin()); title.writeSelectedRows(0, -1, frontPageDocument.leftMargin(), Style.FRONTPAGE_LOGO_POSITION_Y - 150, frontPageWriter.getDirectContent());
private void formatTable(final PdfPTable table) { Rectangle page = document.getPageSize(); table.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); table.getDefaultCell().setPaddingBottom(tablePaddingBottom); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); table.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); table.setSpacingBefore(20); }
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());
@Override public void onEndPage(final PdfWriter writer, final Document document) { try { Image logoImage = Image.getInstance(logo); Rectangle page = document.getPageSize(); PdfPTable head = new PdfPTable(4); head.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); head.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); head.addCell(logoImage); Phrase projectName = new Phrase(project.getName(), FontFactory.getFont( FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY)); Phrase phrase = new Phrase("Sonar PDF Report", FontFactory.getFont( FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY)); head.getDefaultCell().setColspan(2); head.addCell(phrase); head.getDefaultCell().setColspan(1); head.addCell(projectName); head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - 20, writer.getDirectContent()); head.setSpacingAfter(10); } catch (BadElementException e) { LOG.error("Can not generate PDF header", e); } catch (MalformedURLException e) { LOG.error("Can not generate PDF header", e); } catch (IOException e) { LOG.error("Can not generate PDF header", e); } }
addTabs(1); writeStart(HtmlTags.BODY); if (document.leftMargin() > 0) { write(HtmlTags.LEFTMARGIN, String.valueOf(document.leftMargin()));
addTabs(1); writeStart(HtmlTags.BODY); if (document.leftMargin() > 0) { write(HtmlTags.LEFTMARGIN, String.valueOf(document.leftMargin()));
addTabs(1); writeStart(HtmlTags.BODY); if (document.leftMargin() > 0) { write(HtmlTags.LEFTMARGIN, String.valueOf(document.leftMargin()));
public Toc() { toc = new Document(PageSize.A4, 50, 50, 110, 50); content = new PdfPTable(2); Rectangle page = toc.getPageSize(); content.setTotalWidth(page.getWidth() - toc.leftMargin() - toc.rightMargin()); content.getDefaultCell().setUseVariableBorders(true); content.getDefaultCell().setBorderColorBottom(Color.WHITE); content.getDefaultCell().setBorderColorRight(Color.WHITE); content.getDefaultCell().setBorderColorLeft(Color.WHITE); content.getDefaultCell().setBorderColorTop(Color.WHITE); content.getDefaultCell().setBorderWidthBottom(2f); }
foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(), writer.getDirectContent());