List of usage examples for com.itextpdf.text Rectangle getLeft
public float getLeft()
From source file:de.mat.utils.pdftools.PdfAddPageNum.java
License:Mozilla Public License
/** * <h4>FeatureDomain:</h4>//from w w w . j a v a 2 s. co m * PublishingTools * <h4>FeatureDescription:</h4> * adds pagenum with stamper to pages from reader * <h4>FeatureResult:</h4> * <ul> * <li>updates stamper - updates the stamper * </ul> * <h4>FeatureKeywords:</h4> * PDF Publishing * @param reader - reader with the pages * @param stamper - stamper to add the canvas * @param pageOffset - add to pagenumber * @throws DocumentException * @throws IOException */ public void addPageNumber(PdfReader reader, PdfStamper stamper, int pageOffset) throws DocumentException, IOException { // ierate all pages from reader for (int zaehler = 1; zaehler <= reader.getNumberOfPages(); zaehler++) { // read pagesize Rectangle pageSize = reader.getPageSize(zaehler); float xpos = pageSize.getLeft() + pageSize.getWidth() / 2; float ypos = 20; float fontSize = 7; // Default-Positions for --page-width 150mm --page-height 212mm == 601px if (pageSize.getHeight() > 602 || pageSize.getHeight() < 598) { // correct it relative float factor = pageSize.getHeight() / 601; if (LOGGER.isDebugEnabled()) LOGGER.debug(" PageHeight:" + pageSize.getHeight() + " Factor:" + factor); ypos = ypos * factor; fontSize = fontSize * factor; } // add pagenumber-canvas PdfContentByte canvas = stamper.getOverContent(zaehler); BaseFont bf_helv = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false); canvas.setFontAndSize(bf_helv, fontSize); canvas.beginText(); canvas.showTextAligned(PdfContentByte.ALIGN_CENTER, "" + new Integer(zaehler + pageOffset - 1), xpos, ypos, 0); canvas.endText(); } }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
private MediaBox[] getDocumentMediaBox(PdfReader reader, int pages) { MediaBox mbox[] = new MediaBox[pages]; Rectangle rect; for (int x = 0; x < totalPages; x++) { mbox[x] = new MediaBox(); rect = reader.getPageSize(x + 1); mbox[x].top = rect.getTop();//from w w w . j a va2 s . c o m mbox[x].bottom = rect.getBottom(); mbox[x].left = rect.getLeft(); mbox[x].right = rect.getRight(); } return mbox; }
From source file:fr.ybonnel.breizhcamppdf.PdfRenderer.java
License:Apache License
public void render() throws DocumentException, IOException { // Footer//from ww w . j a v a 2 s. c o m pdfWriter.setPageEvent(new PdfPageEventHelper() { @Override public void onEndPage(PdfWriter writer, Document document) { if (writer.getPageNumber() > 1) { Rectangle rect = document.getPageSize(); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("BreizhCamp 2014"), (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() + 18, 0); } } }); createFirstPage(); List<Talk> talksToExplain = createProgrammePages(); createTalksPages(talksToExplain); }
From source file:helpers.PDFHeaderFooter.java
@Override public void onStartPage(PdfWriter writer, Document document) { Rectangle rect = writer.getBoxSize("art"); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(""), rect.getLeft(), rect.getTop(), 0);// ww w. j a v a 2 s . c om ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("Page " + document.getPageNumber(), FontFactory.getFont(FontFactory.TIMES_ITALIC, 5, Font.ITALIC, BaseColor.BLACK)), rect.getRight(), rect.getTop(), 0); }
From source file:helpers.PDFHeaderFooter.java
@Override public void onEndPage(PdfWriter writer, Document document) { Rectangle rect = writer.getBoxSize("art"); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(""), rect.getLeft(), rect.getBottom(), 0);/*from ww w . j a v a2 s .c o m*/ ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("Copyright @" + new SetDateCreated().getYear() + " (Wellington Mapiku)", FontFactory.getFont(FontFactory.TIMES_ROMAN, 7, Font.ITALIC, BaseColor.DARK_GRAY)), rect.getRight(), rect.getBottom(), 0); }
From source file:hsa.awp.admingui.report.util.HeaderFooter.java
License:Open Source License
/** * this method is called by Pageevent./*from w ww . j a v a 2 s . c om*/ * * @param writer write of the document * @param document document it self */ public void onEndPage(PdfWriter writer, Document document) { Rectangle rect = writer.getBoxSize("art"); /* title */ ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase(title, FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16)), rect.getLeft(), rect.getTop() + 20, 0); /* subtitle */ ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase(subtitle, FontFactory.getFont(FontFactory.HELVETICA, 9)), rect.getLeft(), rect.getTop() + 9, 0); /* date */ DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); java.util.Date date = new java.util.Date(); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT, new Phrase(dateFormat.format(date)), rect.getRight(), rect.getTop() + 15, 0); /* pagenumber */ ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(String.format("Seite %d", writer.getPageNumber())), (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 25, 0); }
From source file:ihm.panneaux.GenererPdf.java
public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { PdfContentByte canvas = canvases[PdfPTable.LINECANVAS]; if (top != null) { canvas.saveState();/*www . j a v a 2s .c o m*/ top.applyLineDash(canvas); canvas.moveTo(position.getRight(), position.getTop()); canvas.lineTo(position.getLeft(), position.getTop()); canvas.stroke(); canvas.restoreState(); } if (bottom != null) { canvas.saveState(); bottom.applyLineDash(canvas); canvas.moveTo(position.getRight() - 35, position.getBottom()); canvas.lineTo(position.getLeft(), position.getBottom()); canvas.stroke(); canvas.restoreState(); } if (right != null) { canvas.saveState(); right.applyLineDash(canvas); canvas.moveTo(position.getRight(), position.getTop()); canvas.lineTo(position.getRight(), position.getBottom()); canvas.stroke(); canvas.restoreState(); } if (left != null) { canvas.saveState(); left.applyLineDash(canvas); canvas.moveTo(position.getLeft(), position.getTop()); canvas.lineTo(position.getLeft(), position.getBottom()); canvas.stroke(); canvas.restoreState(); } }
From source file:ke.co.tawi.babblesms.server.utils.export.PdfUtil.java
License:Open Source License
/** * Adds the header and the footer./*from w ww . j a v a 2 s . c o m*/ * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage( * com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document) */ @Override public void onEndPage(PdfWriter writer, Document document) { Rectangle rect = writer.getBoxSize("art"); switch (writer.getPageNumber() % 1) { case 0: ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT, header[0], rect.getRight(), rect.getTop(), 0); break; case 1: ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, header[1], rect.getLeft(), rect.getTop(), 0); break; } ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(String.format("page %d", pagenumber)), (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 18, 0); }
From source file:memoire.HeaderAndFooterPdfPageEventHelper.java
public void onStartPage(PdfWriter pdfWriter, Document document, String HeaderString) { System.out.println("onStartPage() method > Writing header in file"); Rectangle rect = pdfWriter.getBoxSize("rectangle"); // TOP LEFT//from www. j a va2s.c o m ColumnText.showTextAligned(pdfWriter.getDirectContent(), Element.ALIGN_CENTER, new Phrase(""), rect.getLeft(), rect.getTop(), 0); // TOP MEDIUM ColumnText.showTextAligned(pdfWriter.getDirectContent(), Element.ALIGN_CENTER, new Phrase(HeaderString), rect.getRight() / 2, rect.getTop(), 0); // TOP RIGHT ColumnText.showTextAligned(pdfWriter.getDirectContent(), Element.ALIGN_CENTER, new Phrase(""), rect.getRight(), rect.getTop(), 0); }
From source file:memoire.HeaderAndFooterPdfPageEventHelper.java
public void onEndPage(PdfWriter pdfWriter, Document document) { System.out.println("onEndPage() method > Writing footer in file"); Rectangle rect = pdfWriter.getBoxSize("rectangle"); // BOTTOM LEFT ColumnText.showTextAligned(pdfWriter.getDirectContent(), Element.ALIGN_CENTER, new Phrase(""), rect.getLeft() + 15, rect.getBottom(), 0); // BOTTOM MEDIUM ColumnText.showTextAligned(pdfWriter.getDirectContent(), Element.ALIGN_CENTER, new Phrase("BOTTOM MEDIUM"), rect.getRight() / 2, rect.getBottom(), 0); // BOTTOM RIGHT ColumnText.showTextAligned(pdfWriter.getDirectContent(), Element.ALIGN_CENTER, new Phrase(""), rect.getRight() - 10, rect.getBottom(), 0); }