Example usage for com.lowagie.text Rectangle getTop

List of usage examples for com.lowagie.text Rectangle getTop

Introduction

In this page you can find the example usage for com.lowagie.text Rectangle getTop.

Prototype

public float getTop(float margin) 

Source Link

Document

Returns the upper right y-coordinate, considering a given margin.

Usage

From source file:questions.stamppages.IncreaseMediabox.java

public static void main(String[] args) {
    try {/*from   w ww  .j  a  va  2  s .  c o m*/
        PdfDictionary pageDict;
        PdfReader reader = new PdfReader(RESOURCE);
        int n = reader.getNumberOfPages();
        for (int i = 1; i <= n; i++) {
            Rectangle rect = reader.getPageSize(i);
            pageDict = reader.getPageN(i);
            PdfRectangle pdfrect = new PdfRectangle(rect.getLeft(-36), rect.getBottom(-36), rect.getRight(-36),
                    rect.getTop(-36));
            pageDict.put(PdfName.MEDIABOX, pdfrect);
        }
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:questions.stamppages.PageXofYRightAligned.java

public static void main(String[] args) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {/*from  w  w w  .j  a v a 2  s  .  co m*/
        Document document = new Document();
        PdfWriter.getInstance(document, baos);
        document.open();
        BufferedReader reader = new BufferedReader(new FileReader(RESOURCE));
        String line;
        Paragraph p;
        while ((line = reader.readLine()) != null) {
            p = new Paragraph(line);
            p.setAlignment(Element.ALIGN_JUSTIFIED);
            document.add(p);
            document.newPage();
        }
        reader.close();
        document.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    try {
        PdfReader reader = new PdfReader(baos.toByteArray());
        int n = reader.getNumberOfPages();
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        PdfContentByte page;
        Rectangle rect;
        BaseFont bf = BaseFont.createFont();
        for (int i = 1; i < n + 1; i++) {
            page = stamper.getOverContent(i);
            rect = reader.getPageSizeWithRotation(i);
            page.beginText();
            page.setFontAndSize(bf, 12);
            page.showTextAligned(Element.ALIGN_RIGHT, "page " + i + " of " + n, rect.getRight(36),
                    rect.getTop(32), 0);
            page.endText();
        }
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}