Example usage for com.itextpdf.text Rectangle getTop

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

Introduction

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

Prototype

public float getTop() 

Source Link

Document

Returns the upper right y-coordinate.

Usage

From source file:org.me.modelos.HeaderFooterPageEvent.java

@Override
public void onStartPage(PdfWriter writer, Document document) {

    Rectangle rect = writer.getBoxSize("art");
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
            new Phrase(motelNombre + " " + direccion + " " + telefono, font), rect.getLeft(), rect.getTop(), 0);
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(fecha, font),
            rect.getRight(), rect.getTop(), 0);
}

From source file:ro.ldir.chartpackage.GarbagePackageBuilder.java

License:Open Source License

public void writePDF(OutputStream out)
        throws DocumentException, MalformedURLException, XPathExpressionException, IOException {
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, "Cp1250", BaseFont.NOT_EMBEDDED);
    final Font hfFont = new Font(bf, 8, Font.NORMAL, BaseColor.GRAY);

    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    PdfWriter writer = PdfWriter.getInstance(document, out);
    writer.setBoxSize("art", new Rectangle(36, 54, 559, 788));

    writer.setPageEvent(new PdfPageEventHelper() {
        private int page = 0;

        @Override//from   w  w w  .ja  v  a  2 s . c  om
        public void onEndPage(PdfWriter writer, Document arg1) {
            page++;
            Rectangle rect = writer.getBoxSize("art");
            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
                    new Phrase("Pachet mormane - \u00a9 Let's Do It, Romania!", hfFont),
                    (rect.getLeft() + rect.getRight()) / 2, rect.getTop() + 18, 0);
            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
                    new Phrase("- " + page + " -", hfFont), (rect.getLeft() + rect.getRight()) / 2,
                    rect.getBottom() - 18, 0);
        }
    });

    document.open();
    document.addAuthor("Let's Do It, Romania!");
    document.addTitle("Pachet mormane");
    document.addCreationDate();

    Font titleFont = new Font(bf, 24, Font.BOLD);
    Font noteFont = new Font(bf, 12, Font.NORMAL, BaseColor.RED);
    Font headerFont = new Font(bf, 12, Font.BOLD);
    Font normalFont = new Font(bf, 11);
    Font defFont = new Font(bf, 11, Font.BOLD);
    Paragraph par;
    int page = 0;

    for (Garbage garbage : garbages) {
        par = new Paragraph();
        par.setAlignment(Element.ALIGN_CENTER);
        par.add(new Chunk("Morman " + garbage.getGarbageId() + "\n", titleFont));
        par.add(new Chunk("Citi\u0163i cu aten\u0163ie!", noteFont));
        document.add(par);

        par = new Paragraph();
        par.setSpacingBefore(20);
        par.add(new Chunk("1. Date generale\n", headerFont));
        par.add(new Chunk("Jude\u0163ul: ", defFont));
        par.add(new Chunk(garbage.getCounty().getName() + "\n", normalFont));
        par.add(new Chunk("Comuna: ", defFont));
        par.add(new Chunk(garbage.getTown().getName() + "\n", normalFont));
        if (garbage.getChartedArea() != null) {
            par.add(new Chunk("Zona cartare: ", defFont));
            par.add(new Chunk(garbage.getChartedArea().getName() + "\n", normalFont));
        }
        par.add(new Chunk("Pozi\u0163ie: ", defFont));
        par.add(new Chunk(garbage.getY() + ", " + garbage.getX() + "\n", normalFont));
        par.add(new Chunk("Descriere:\n", defFont));
        par.add(new Phrase(garbage.getDescription() + "\n", normalFont));
        par.add(new Chunk("Componen\u0163\u0103 gunoi:\n", defFont));
        List list = new List();
        list.add(new ListItem(
                new Chunk("Procent plastic: " + garbage.getPercentagePlastic() + "%", normalFont)));
        list.add(new ListItem(
                new Chunk("Procent sticl\u0103: " + garbage.getPercentageGlass() + "%", normalFont)));
        list.add(new ListItem(new Chunk("Procent metale: " + garbage.getPercentageMetal() + "%", normalFont)));
        list.add(new ListItem(
                new Chunk("Procent nereciclabile: " + garbage.getPercentageWaste() + "%", normalFont)));
        par.add(list);
        document.add(par);

        par = new Paragraph();
        par.setSpacingBefore(20);
        par.add(new Chunk("2. Indica\u0163ii rutiere\n", headerFont));
        Image img = Image.getInstance(getImage(garbage));
        img.scaleToFit((float) (PageSize.A4.getWidth() * .75), (float) (PageSize.A4.getHeight() * .75));
        img.setAlignment(Element.ALIGN_CENTER);
        par.add(img);
        document.add(par);

        if (page < garbages.size() - 1)
            document.newPage();
        page++;
    }

    document.close();
}

From source file:timeclock.reports.HeaderFooter.java

/**
 * Adds the header and the footer.//  ww  w  . jav a  2s  .  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");

    // Show page header at top center
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, header,
            (rect.getLeft() + rect.getRight()) / 2, rect.getTop() + 12, 0);

    // Show page number at bottom center
    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:watermarkpdf.FXMLDocumentController.java

@FXML
private void handleButtonAction(ActionEvent event) throws DocumentException, IOException {
    if (tfPhrase.getLength() > 0) {
        lbl_Result.setText("");
        PdfReader reader = new PdfReader(tf_PathFile.getText());
        Rectangle mediabox = reader.getPageSize(1);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(
                tf_PathFile.getText().substring(0, tf_PathFile.getLength() - 4) + "_out.pdf"));
        stamper.setRotateContents(false);
        BaseFont bf = BaseFont.createFont("TNR.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        Font font = new Font(bf);
        int iPos = tfPhrase.getText().indexOf('#');
        for (int i = 1; i <= reader.getNumberOfPages(); i++) {
            PdfContentByte canvas = stamper.getOverContent(i);
            if (iPos >= 0) {
                if (cbox_LU.isSelected()) {
                    switch (i) {
                    case 1:
                        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                                new Phrase((tfPhrase.getText().substring(0, iPos - 5)
                                        + "? ? "
                                        + tfPhrase.getText().substring(iPos + 1)), font),
                                mediabox.getRight() / 3, mediabox.getTop() - 40, 0);
                        break;
                    case 2:
                        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                                new Phrase((tfPhrase.getText().substring(0, iPos - 5)
                                        + " ? "
                                        + tfPhrase.getText().substring(iPos + 1)), font),
                                mediabox.getRight() / 3, mediabox.getTop() - 40, 0);
                        break;
                    default:
                        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                                new Phrase((tfPhrase.getText().substring(0, iPos) + (i - 1)
                                        + tfPhrase.getText().substring(iPos + 1)), font),
                                mediabox.getRight() / 3, mediabox.getTop() - 40, 0);
                    }//w ww .ja  v  a  2  s . co  m
                } else {
                    if (i == 1)
                        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                                new Phrase((tfPhrase.getText().substring(0, iPos - 5)
                                        + " ? "
                                        + tfPhrase.getText().substring(iPos + 1)), font),
                                mediabox.getRight() / 3, mediabox.getTop() - 40, 0);
                    else
                        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                                new Phrase((tfPhrase.getText().substring(0, iPos) + (i)
                                        + tfPhrase.getText().substring(iPos + 1)), font),
                                mediabox.getRight() / 3, mediabox.getTop() - 40, 0);
                }

            } else {
                ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(tfPhrase.getText(), font),
                        mediabox.getRight() / 3, mediabox.getTop() - 40, 0);
            }
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(tf_append.getText(), font),
                    mediabox.getRight() * 2 / 3, mediabox.getTop() - 20, 0);
        }
        stamper.close();
        reader.close();
        if (tf_PagePrint.getLength() > 0) {
            reader = new PdfReader(
                    tf_PathFile.getText().substring(0, tf_PathFile.getLength() - 4) + "_out.pdf");
            reader.selectPages(tf_PagePrint.getText());
            stamper = new PdfStamper(reader, new FileOutputStream(
                    tf_PathFile.getText().substring(0, tf_PathFile.getLength() - 4) + "_out_cut.pdf"));
            stamper.close();
            reader.close();
        }
        lbl_Result.setText("  ");
    }
}