Example usage for com.lowagie.text Rectangle getBottom

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

Introduction

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

Prototype

public float getBottom(float margin) 

Source Link

Document

Returns the lower left y-coordinate, considering a given margin.

Usage

From source file:classroom.filmfestival_c.Movies19.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // step 1/*  w w  w  .j a v  a  2  s  .c o  m*/
    Rectangle rect = PageSize.A4.rotate();
    Document document = new Document(rect);
    try {
        // step 2
        OutputStream os = new FileOutputStream(RESULT);
        PdfWriter writer = PdfWriter.getInstance(document, os);
        Rectangle art = new Rectangle(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36));
        writer.setBoxSize("art", art);
        // step 3
        document.open();
        // step 4

        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery(
                "select distinct festival.id.day from FestivalScreening as festival order by festival.id.day");
        java.util.List<Date> days = q.list();

        for (Date day : days) {
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(day);
            if (gc.get(GregorianCalendar.YEAR) != YEAR)
                continue;
            createSheet(session, day, writer);
            document.newPage();
        }
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_c.Movies20.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // step 1//from   ww w.  j a  va2 s  .  c o m
    Rectangle rect = PageSize.A4.rotate();
    Document document = new Document(rect);
    try {
        // step 2
        OutputStream os = new FileOutputStream(RESULT);
        PdfWriter writer = PdfWriter.getInstance(document, os);
        Rectangle art = new Rectangle(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36));
        writer.setBoxSize("art", art);
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        // step 3
        document.open();
        // step 4

        PdfOutline root = writer.getDirectContent().getRootOutline();

        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery(
                "select distinct festival.id.day from FestivalScreening as festival order by festival.id.day");
        java.util.List<Date> days = q.list();

        for (Date day : days) {
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(day);
            if (gc.get(GregorianCalendar.YEAR) != YEAR)
                continue;
            createSheet(session, day, writer);
            new PdfOutline(root, new PdfDestination(PdfDestination.FIT), day.toString());
            document.newPage();
        }
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:org.kuali.coeus.common.impl.print.watermark.WatermarkServiceImpl.java

License:Open Source License

/**
 * This method is for setting the properties of watermark Text.
 *//*  w ww  .ja v  a 2 s  .com*/
private void decoratePdfWatermarkText(PdfContentByte pdfContentByte, Rectangle rectangle,
        WatermarkBean watermarkBean) {
    float x, y, x1, y1, angle;
    final float OPACITY = 0.3f;
    PdfGState pdfGState = new PdfGState();
    pdfGState.setFillOpacity(OPACITY);
    int pageWidth = (int) rectangle.getWidth();
    int pageHeight = (int) rectangle.getHeight();
    try {
        if (watermarkBean.getType().equalsIgnoreCase(WatermarkConstants.WATERMARK_TYPE_TEXT)) {
            pdfContentByte.beginText();
            pdfContentByte.setGState(pdfGState);
            Color fillColor = watermarkBean.getFont().getColor() == null
                    ? WatermarkConstants.DEFAULT_WATERMARK_COLOR
                    : watermarkBean.getFont().getColor();
            pdfContentByte.setColorFill(fillColor);

            if (watermarkBean.getPosition().equals(WatermarkConstants.WATERMARK_POSITION_FOOTER)) {

                pdfContentByte.setFontAndSize(watermarkBean.getFont().getBaseFont(),
                        watermarkBean.getPositionFont().getSize());
                if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_CENTER)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_CENTER, watermarkBean.getText(),
                            (rectangle.getLeft(rectangle.getBorderWidthLeft())
                                    + rectangle.getRight(rectangle.getBorderWidthRight())) / 2,
                            rectangle.getBottom(rectangle.getBorderWidthBottom()
                                    + watermarkBean.getPositionFont().getSize()),
                            0);
                } else if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_RIGHT)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_RIGHT, watermarkBean.getText(),
                            rectangle.getRight(rectangle.getBorderWidthRight()),
                            rectangle.getBottom(rectangle.getBorderWidthBottom()
                                    + watermarkBean.getPositionFont().getSize()),
                            0);
                } else if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_LEFT)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_LEFT, watermarkBean.getText(),
                            rectangle.getLeft(rectangle.getBorderWidthLeft()),
                            rectangle.getBottom(rectangle.getBorderWidthBottom()
                                    + watermarkBean.getPositionFont().getSize()),
                            0);
                }
            } else if (watermarkBean.getPosition().equals(WatermarkConstants.WATERMARK_POSITION_HEADER)) {
                pdfContentByte.setFontAndSize(watermarkBean.getFont().getBaseFont(),
                        watermarkBean.getPositionFont().getSize());
                if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_CENTER)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_CENTER, watermarkBean.getText(),
                            (rectangle.getLeft(rectangle.getBorderWidthLeft())
                                    + rectangle.getRight(rectangle.getBorderWidthRight())) / 2,
                            rectangle.getTop(
                                    rectangle.getBorderWidthTop() + watermarkBean.getPositionFont().getSize()),
                            0);
                } else if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_RIGHT)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_RIGHT, watermarkBean.getText(),
                            rectangle.getRight(rectangle.getBorderWidthRight()),
                            rectangle.getTop(
                                    rectangle.getBorderWidthTop() + watermarkBean.getPositionFont().getSize()),
                            0);
                } else if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_LEFT)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_LEFT, watermarkBean.getText(),
                            rectangle.getLeft(rectangle.getBorderWidthLeft()),
                            rectangle.getTop(
                                    rectangle.getBorderWidthTop() + watermarkBean.getPositionFont().getSize()),
                            0);
                }
            } else {
                pdfContentByte.setFontAndSize(watermarkBean.getFont().getBaseFont(),
                        watermarkBean.getFont().getSize());
                int textWidth = (int) pdfContentByte.getEffectiveStringWidth(watermarkBean.getText(), false);
                int diagonal = (int) Math.sqrt((pageWidth * pageWidth) + (pageHeight * pageHeight));
                int pivotPoint = (diagonal - textWidth) / 2;

                angle = (float) Math.atan((float) pageHeight / pageWidth);

                x = (float) (pivotPoint * pageWidth) / diagonal;
                y = (float) (pivotPoint * pageHeight) / diagonal;

                x1 = (float) (((float) watermarkBean.getFont().getSize() / 2) * Math.sin(angle));
                y1 = (float) (((float) watermarkBean.getFont().getSize() / 2) * Math.cos(angle));

                pdfContentByte.showTextAligned(Element.ALIGN_LEFT, watermarkBean.getText(), x + x1, y - y1,
                        (float) Math.toDegrees(angle));
            }
            pdfContentByte.endText();
        }
    } catch (Exception exception) {
        LOG.error("Exception occured in WatermarkServiceImpl. Water mark Exception: " + exception.getMessage());
    }

}

From source file:questions.forms.FormWithTooltips.java

/**
 * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell,
 *      com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
 *//*from www. jav a2 s  . c o m*/
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] cb) {
    kid.setWidget(new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding),
            rect.getTop(padding)), PdfAnnotation.HIGHLIGHT_INVERT);
    kid.setUserName(tooltip);
    try {
        parent.addKid(kid);
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:questions.forms.KidsOnDifferentPages.java

public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] cb) {
    kid.setWidget(new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding),
            rect.getTop(padding)), PdfAnnotation.HIGHLIGHT_INVERT);
}

From source file:questions.stamppages.BookmarksToTOC1.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {// w  ww  .  jav  a  2  s.c  o  m
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        writer.setPageEvent(new ParagraphBookmarkEvents(false));
        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.add(Chunk.NEWLINE);
        }
        reader.close();
        document.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    try {
        PdfReader reader = new PdfReader(baos.toByteArray());
        Rectangle rect = reader.getPageSizeWithRotation(1);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        stamper.insertPage(1, rect);
        ColumnText column = new ColumnText(stamper.getOverContent(1));
        column.setSimpleColumn(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36));
        column.addElement(new Paragraph("TABLE OF CONTENTS"));
        List<Map> list = SimpleBookmark.getBookmark(reader);
        Chunk link;
        PdfAction action;
        String info;
        int p = 1;
        float y = 10;
        for (Map<String, String> bookmark : list) {
            link = new Chunk(bookmark.get("Title"));
            info = bookmark.get("Page");
            p = Integer.parseInt(info.substring(0, info.indexOf(' ')));
            y = Float.parseFloat(info.substring(info.lastIndexOf(' ') + 1) + "f");
            action = PdfAction.gotoLocalPage(p, new PdfDestination(PdfDestination.FITH, y),
                    stamper.getWriter());
            link.setAction(action);
            column.addElement(new Paragraph(link));
        }
        column.go();
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:questions.stamppages.BookmarksToTOC2.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {/*from  w w  w  . j av a2 s .c  o m*/
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        writer.setPageEvent(new ParagraphBookmarkEvents(true));
        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.add(Chunk.NEWLINE);
        }
        reader.close();
        document.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    try {
        PdfReader reader = new PdfReader(baos.toByteArray());
        Rectangle rect = reader.getPageSizeWithRotation(1);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        stamper.insertPage(1, rect);
        ColumnText column = new ColumnText(stamper.getOverContent(1));
        column.setSimpleColumn(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36));
        column.addElement(new Paragraph("TABLE OF CONTENTS"));
        List<Map> list = SimpleBookmark.getBookmark(reader);
        Chunk link;
        String dest;
        for (Map<String, String> bookmark : list) {
            link = new Chunk(bookmark.get("Title"));
            dest = bookmark.get("Named");
            link.setAction(PdfAction.gotoLocalPage(dest, false));
            column.addElement(new Paragraph(link));
        }
        column.go();
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:questions.stamppages.IncreaseMediabox.java

public static void main(String[] args) {
    try {/*from  w w w  . ja v  a 2  s . com*/
        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();
    }
}