Example usage for com.itextpdf.text Rectangle getBottom

List of usage examples for com.itextpdf.text Rectangle getBottom

Introduction

In this page you can find the example usage for com.itextpdf.text Rectangle getBottom.

Prototype

public float getBottom() 

Source Link

Document

Returns the lower left y-coordinate.

Usage

From source file:de.domjos.schooltools.core.utils.fileUtils.PDFBuilder.java

License:Open Source License

public void onEndPage(PdfWriter writer, Document document) {
    try {/*w  w  w . j a  v  a 2  s .  c  o  m*/
        Rectangle rect = writer.getBoxSize("art");
        Image img = Image.getInstance(Converter.convertDrawableToByteArray(this.context, R.drawable.icon));
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(img, 0, 0));
        ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, phrase, rect.getLeft(),
                rect.getBottom(), 0);
        ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
                new Phrase(String
                        .valueOf(this.context.getString(R.string.api_page) + " " + document.getPageNumber())),
                rect.getRight(), rect.getBottom(), 0);
    } catch (Exception ex) {
        Helper.printException(context, ex);
    }
}

From source file:de.gbv.marginalia.Marginalia.java

License:Open Source License

/**
 * Inspect a PDF file and write the info to a writer
 * @param writer Writer to a text file/*from  w w  w  .  j a  va  2s.  com*/
 * @param filename Path to the PDF file
 * @throws IOException
 */
public static void inspect(PrintWriter writer, String filename) throws IOException, SAXException {
    //        writer.println(filename);
    writer.flush();

    PdfReader reader = new PdfReader(filename);

    ContentHandler xmlhandler = new SimpleXMLWriter(writer);
    xmlhandler.startDocument();

    SimpleXMLCreator xml = new SimpleXMLCreator(xmlhandler, Annotation.namespaces, true);

    /*
            writer.println("Number of pages: "+reader.getNumberOfPages());
            Rectangle mediabox = reader.getPageSize(1);
            writer.print("Size of page 1: [");
            writer.print(mediabox.getLeft());
            writer.print(',');
            writer.print(mediabox.getBottom());
            writer.print(',');
            writer.print(mediabox.getRight());
            writer.print(',');
            writer.print(mediabox.getTop());
            writer.println("]");
            writer.print("Rotation of page 1: ");
            writer.println(reader.getPageRotation(1));
            writer.print("Page size with rotation of page 1: ");
            writer.println(reader.getPageSizeWithRotation(1));
            writer.println();
            writer.flush();
    */
    List<Annotation> annots = new LinkedList<Annotation>();
    xml.startElement("annots");

    // TODO: The following elements may be added:
    // - optionally write <f href="Document.pdf"/>
    // - optionally write <ids original="ID" modified="ID" />

    xml.startElement("m", "pages");
    for (int pageNum = 1; pageNum <= reader.getNumberOfPages(); pageNum++) {
        PdfDictionary pageDic = reader.getPageN(pageNum);

        Map<String, String> attr = new HashMap<String, String>();
        attr.put("number", "" + pageNum);
        attr.put("rotate", "" + reader.getPageRotation(pageNum));

        Rectangle mediabox = reader.getPageSize(pageNum);
        attr.put("left", "" + mediabox.getLeft());
        attr.put("bottom", "" + mediabox.getBottom());
        attr.put("right", "" + mediabox.getRight());
        attr.put("top", "" + mediabox.getTop());

        xml.contentElement("m", "page", "", attr);

        PdfArray rawannots = pageDic.getAsArray(PdfName.ANNOTS);
        if (rawannots == null || rawannots.isEmpty()) {
            // writer.println("page "+pageNum+" contains no annotations");
            continue;
        }

        // writer.println("page "+pageNum+" has "+rawannots.size()+" annotations");

        for (int i = 0; i < rawannots.size(); i++) {
            PdfObject obj = rawannots.getDirectObject(i);
            if (!obj.isDictionary())
                continue;
            Annotation a = new Annotation((PdfDictionary) obj, pageNum);
            annots.add(a);
        }

        /**
        // Now we have all highlight and similar annotations, we need
        // to find out what words are actually highlighted! PDF in fact
        // is a dump format to express documents.
        // For some hints see
        // http://stackoverflow.com/questions/4028240/extract-each-column-of-a-pdf-file
                
        // We could reuse code from LocationTextExtractionStrategy (TODO)
        // LocationTextExtractionStrategy extr = new LocationTextExtractionStrategy();
        String fulltext = PdfTextExtractor.getTextFromPage(reader,pageNum);//,extr
        writer.println(fulltext);
        */
    }
    xml.endElement();

    for (Annotation a : annots) {
        a.serializeXML(xmlhandler);
    }
    // TODO: add page information (page size and orientation)

    xml.endAll();
}

From source file:de.jost_net.JVerein.io.HeaderFooter.java

License:Open Source License

/**
 * Adds the header and the footer.//from   w ww  .j  av a2s  .  c om
 * 
 */
@Override
public void onEndPage(PdfWriter writer, Document document) {
    Rectangle rect = document.getPageSize();
    switch (writer.getPageNumber() % 2) {
    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;
    }
    float left = rect.getLeft() + document.leftMargin();
    float right = rect.getRight() - document.rightMargin();
    float bottom = rect.getBottom() + document.bottomMargin();
    PdfContentByte pc = writer.getDirectContent();
    pc.setColorStroke(BaseColor.BLACK);
    pc.setLineWidth(0.5f);
    pc.moveTo(left, bottom - 5);
    pc.lineTo(right, bottom - 5);
    pc.stroke();
    pc.moveTo(left, bottom - 25);
    pc.lineTo(right, bottom - 25);
    pc.stroke();

    ColumnText.showTextAligned(pc, Element.ALIGN_CENTER,
            new Phrase(footer + " " + pagenumber, Reporter.getFreeSans(7)), (left + right) / 2, bottom - 18, 0);
}

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   www.j  av  a  2s .  c o  m
        mbox[x].bottom = rect.getBottom();
        mbox[x].left = rect.getLeft();
        mbox[x].right = rect.getRight();
    }
    return mbox;
}

From source file:fenix.planner.pdf.PDFGenerator.java

License:Open Source License

private void addPageNumbers(PdfReader reader, PdfCopy copy) {
    int pageCount = reader.getNumberOfPages();
    PdfImportedPage page;// www . ja v  a  2  s.  com
    PdfCopy.PageStamp stamp;

    for (int i = 1; i <= pageCount; ++i) {
        Rectangle rect = reader.getBoxSize(i, "art");
        page = copy.getImportedPage(reader, i);
        stamp = copy.createPageStamp(page);
        // add page numbers
        ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_RIGHT,
                new Phrase(String.format("%d / %d", i, pageCount), footerFont), rect.getRight(),
                rect.getBottom() + 5, 0);
        try {
            stamp.alterContents();
            copy.addPage(page);
        } catch (BadPdfFormatException | IOException ex) {
            throw new PDFGenerationException("Error adding page number to page " + i, ex);
        }
    }
}

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 onEndPage(PdfWriter writer, Document document) {
    Rectangle rect = writer.getBoxSize("art");
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(""), rect.getLeft(),
            rect.getBottom(), 0);
    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./*  w  w  w.  ja  va  2 s .c o  m*/
 *
 * @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();//from ww w .  j  a va 2  s. co  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 va2s .  co 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);
}