Example usage for com.itextpdf.text Document bottom

List of usage examples for com.itextpdf.text Document bottom

Introduction

In this page you can find the example usage for com.itextpdf.text Document bottom.

Prototype


public float bottom() 

Source Link

Document

Returns the lower left y-coordinate.

Usage

From source file:com.afrisoftech.lib.HeaderFooterHelper.java

public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte cb = writer.getDirectContent();
    // Phrase header = new Phrase("this is a header", ffont);
    // Phrase footer = new Phrase("this is a footer", ffont);
    ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, header,
            (document.right() - document.left()) / 2 + document.leftMargin(), document.top() + 10, 0);
    ColumnText.showTextAligned(cb, Element.ALIGN_CENTER,
            new Phrase(footer.getContent() + " " + String.valueOf(writer.getPageNumber())),
            (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() - 10, 0);
}

From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java

License:Open Source License

private void writeDocument(Document document, File targetFile) {
    boolean frame = detailTabfolder.getSelectionIndex() == 1;
    try (FileOutputStream out = new FileOutputStream(targetFile)) {
        PdfWriter writer = PdfWriter.getInstance(document, out);
        document.open();//from w  ww . ja va 2s  .  c  o m
        writer.setPageEvent(new PdfPageEventHelper() {
            int pageNo = 0;
            com.itextpdf.text.Font ffont = new com.itextpdf.text.Font(
                    com.itextpdf.text.Font.FontFamily.HELVETICA, 9, com.itextpdf.text.Font.NORMAL,
                    BaseColor.DARK_GRAY);

            @Override
            public void onEndPage(PdfWriter w, Document d) {
                PdfContentByte cb = w.getDirectContent();
                Phrase footer = new Phrase(String.valueOf(++pageNo), ffont);
                ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer,
                        (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom(), 0);
            }
        });
        String tit = NLS.bind(Messages.ExhibitionEditDialog_exhibition_name, nameField.getText());
        Paragraph p = new Paragraph(tit,
                FontFactory.getFont(FontFactory.HELVETICA, 14, com.itextpdf.text.Font.BOLD, BaseColor.BLACK));
        p.setAlignment(Element.ALIGN_CENTER);
        p.setSpacingAfter(8);
        document.add(p);
        String subtitle = NLS.bind(Messages.ExhibitionEditDialog_image_list, Constants.DFDT.format(new Date()),
                frame ? Messages.ExhibitionEditDialog_image_sizes : Messages.ExhibitionEditDialog_frame_sizes);
        p = new Paragraph(subtitle,
                FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK));
        p.setAlignment(Element.ALIGN_CENTER);
        p.setSpacingAfter(14);
        document.add(p);
        p = new Paragraph(descriptionField.getText(),
                FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK));
        p.setAlignment(Element.ALIGN_CENTER);
        p.setSpacingAfter(10);
        document.add(p);
        p = new Paragraph(infoField.getText(),
                FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK));
        p.setAlignment(Element.ALIGN_CENTER);
        p.setSpacingAfter(10);
        document.add(p);
        IDbManager db = Core.getCore().getDbManager();
        List<Wall> walls = current.getWall();
        Wall[] sortedWalls = walls.toArray(new Wall[walls.size()]);
        Arrays.sort(sortedWalls, new Comparator<Wall>() {
            public int compare(Wall o1, Wall o2) {
                return o1.getLocation().compareToIgnoreCase(o2.getLocation());
            }
        });
        for (Wall wall : sortedWalls) {
            p = new Paragraph(wall.getLocation(), FontFactory.getFont(FontFactory.HELVETICA, 12,
                    com.itextpdf.text.Font.BOLD, BaseColor.BLACK));
            p.setAlignment(Element.ALIGN_LEFT);
            p.setSpacingAfter(12);
            document.add(p);
            PdfPTable table = new PdfPTable(7);
            // table.setBorderWidth(1);
            // table.setBorderColor(new Color(224, 224, 224));
            // table.setPadding(5);
            // table.setSpacing(0);
            table.setWidths(new int[] { 8, 33, 13, 13, 20, 13, 20 });
            table.addCell(createTableHeader(Messages.ExhibitionEditDialog_No, Element.ALIGN_RIGHT));
            table.addCell(createTableHeader(Messages.ExhibitionEditDialog_title, Element.ALIGN_LEFT));
            table.addCell(createTableHeader(Messages.ExhibitionEditDialog_xpos, Element.ALIGN_RIGHT));
            table.addCell(createTableHeader(Messages.ExhibitionEditDialog_height, Element.ALIGN_RIGHT));
            table.addCell(createTableHeader(Messages.ExhibitionEditDialog_size, Element.ALIGN_RIGHT));
            table.addCell(createTableHeader(Messages.ExhibitionEditDialog_dpi, Element.ALIGN_RIGHT));
            table.addCell(createTableHeader("", Element.ALIGN_LEFT)); //$NON-NLS-1$
            // table.endHeaders();
            List<ExhibitImpl> exhibits = new ArrayList<ExhibitImpl>();
            for (String exhibitId : wall.getExhibit()) {
                ExhibitImpl exhibit = db.obtainById(ExhibitImpl.class, exhibitId);
                if (exhibit != null)
                    exhibits.add(exhibit);
            }
            Collections.sort(exhibits, new Comparator<ExhibitImpl>() {
                public int compare(ExhibitImpl e1, ExhibitImpl e2) {
                    return ((Exhibit) e1).getX() - ((Exhibit) e2).getX();
                }
            });
            int no = 1;
            for (ExhibitImpl exhibit : exhibits) {
                int tara = computeTara(frame, exhibit);
                table.addCell(createTableCell(String.valueOf(no++), Element.ALIGN_RIGHT));
                table.addCell(createTableCell(exhibit.getTitle(), Element.ALIGN_LEFT));
                af.setMaximumFractionDigits(2);
                af.setMinimumFractionDigits(2);
                String x = af.format((exhibit.getX() - tara) / 1000d);
                table.addCell(createTableCell(NLS.bind("{0} m", x), Element.ALIGN_RIGHT)); //$NON-NLS-1$
                String y = af.format((exhibit.getY() + tara) / 1000d);
                table.addCell(createTableCell(NLS.bind("{0} m", y), Element.ALIGN_RIGHT)); //$NON-NLS-1$
                af.setMaximumFractionDigits(1);
                af.setMinimumFractionDigits(1);
                String h = af.format((exhibit.getHeight() + 2 * tara) / 10d);
                int width = exhibit.getWidth();
                String w = af.format((width + 2 * tara) / 10d);
                table.addCell(createTableCell(NLS.bind("{0} x {1} cm", w, h), Element.ALIGN_RIGHT)); //$NON-NLS-1$
                AssetImpl asset = dbManager.obtainAsset(exhibit.getAsset());
                if (asset != null) {
                    int pixels = asset.getWidth();
                    double dpi = pixels * 25.4d / width;
                    table.addCell(createTableCell(String.valueOf((int) dpi), Element.ALIGN_RIGHT));
                } else
                    table.addCell(""); //$NON-NLS-1$
                table.addCell(createTableCell(exhibit.getSold() ? Messages.ExhibitionEditDialog_sold : "", //$NON-NLS-1$
                        Element.ALIGN_LEFT));
            }
            document.add(table);
        }
        document.close();
    } catch (DocumentException e) {
        UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_internal_error_writing_pdf, e);
    } catch (IOException e) {
        UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_io_error_writing_pdf, e);
    }
}

From source file:com.dandymadeproductions.ajqvue.io.PDFDataTableDumpThread.java

License:Open Source License

public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte cb;/*from  www.j  a v  a 2  s.  c  om*/
    String text;
    float textSize;
    float textBase;
    float adjust;

    cb = writer.getDirectContent();
    textBase = document.bottom() - 20;

    cb.beginText();
    cb.setFontAndSize(BASE_FONT, 12);
    adjust = BASE_FONT.getWidthPoint("000", 12);

    cb.setTextMatrix(document.bottom(), textBase);
    cb.showText("Produced by iTextpdf");

    text = "Page " + writer.getPageNumber() + " of ";
    textSize = BASE_FONT.getWidthPoint(text, 12);
    cb.setTextMatrix(document.right() - textSize - adjust, textBase);
    cb.showText(text);

    cb.endText();

    if (pdfTemplate != null)
        cb.addTemplate(pdfTemplate, document.right() - adjust, textBase);
}

From source file:com.dandymadeproductions.myjsqlview.io.PDFDataTableDumpThread.java

License:Open Source License

public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte cb = writer.getDirectContent();
    String text = "Page " + writer.getPageNumber() + " of ";
    float textSize = BASE_FONT.getWidthPoint(text, 12);
    float textBase = document.bottom() - 20;
    cb.beginText();//from   w ww.  j a  v a  2s .co  m
    cb.setFontAndSize(BASE_FONT, 12);
    float adjust = BASE_FONT.getWidthPoint("000", 12);
    cb.setTextMatrix(document.right() - textSize - adjust, textBase);
    cb.showText(text);
    cb.endText();
    cb.addTemplate(pdfTemplate, document.right() - adjust, textBase);
}

From source file:com.softwaremagico.tm.pdf.complete.events.FooterEvent.java

License:Open Source License

/**
 * Adds a footer to every page//  w  ww .  ja v  a 2s .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) {
    if (writer.getPageNumber() % 2 == 0) {
        PdfContentByte cb = writer.getDirectContent();
        Phrase footer = new Phrase(
                "Created using 'Think Machine'"
                        + (Version.getVersion() != null ? " v" + Version.getVersion() : ""),
                new Font(FadingSunsTheme.getFooterFont(), FadingSunsTheme.FOOTER_FONT_SIZE));
        ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer,
                (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() + 20, 0);
    }
}

From source file:com.softwaremagico.tm.pdf.complete.events.PartyFooterEvent.java

License:Open Source License

/**
 * Adds a footer to every page/*from  w w  w .  java 2s.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) {
    PdfContentByte cb = writer.getDirectContent();
    Phrase footer = new Phrase(
            party.getPartyName() + " - Created using 'Think Machine'"
                    + (Version.getVersion() != null ? " v" + Version.getVersion() : ""),
            new Font(FadingSunsTheme.getFooterFont(), FadingSunsTheme.FOOTER_FONT_SIZE));
    ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer,
            (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() + bottomMargin,
            0);
}

From source file:com.tomasz.drag.triballocommanderro.controller.MakerPDF.java

public static void printToPDF(ArrayList<Person> workers, EventGig event) throws IOException, DocumentException {
    String filename = event.getName() + ".pdf";
    String path = event.getData() + " " + event.getName() + "//";

    Document document = new Document();
    // step 2//from   w  w  w  . ja v a  2 s.  co  m
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path + filename));
    // step 3
    document.open();
    // step 4
    ColumnText column = new ColumnText(writer.getDirectContent());

    float[][] x = { { document.left(), document.left() + 230 }, { document.right() - 230, document.right() } };
    for (Person person : workers) {
        column.addElement(MakerPDF.createTable(person, event));
    }
    int count = 0;
    float height = 0;
    int status = ColumnText.START_COLUMN;
    while (ColumnText.hasMoreText(status)) {
        column.setSimpleColumn(x[count][0], document.bottom(), x[count][1], document.top() - height - 10);
        // render as much content as possible
        status = column.go();
        // go to a new page if you've reached the last column
        if (++count > 1) {
            count = 0;
            document.newPage();
        }
    }
    document.newPage();
    document.close();
}

From source file:com.vectorprint.report.itext.EventHelper.java

License:Open Source License

/**
 * prints a footer table with a line at the top, a date and page numbering, second cell will be right aligned
 *
 * @see #PAGEFOOTERTABLEKEY//from   ww  w.ja va  2 s.c o  m
 * @see #PAGEFOOTERSTYLEKEY
 *
 * @param writer
 * @param document
 * @throws DocumentException
 * @throws VectorPrintException
 */
protected void renderFooter(PdfWriter writer, Document document)
        throws DocumentException, VectorPrintException, InstantiationException, IllegalAccessException {
    if (!debugHereAfter && !failuresHereAfter) {
        PdfPTable footerTable = elementProducer.createElement(null, PdfPTable.class,
                getStylers(PAGEFOOTERTABLEKEY));

        footerTable.addCell(createFooterCell(ValueHelper.createDate(new Date())));

        String pageText = writer.getPageNumber() + getSettings().getProperty(" of ", UPTO);

        PdfPCell c = createFooterCell(pageText);
        c.setHorizontalAlignment(Element.ALIGN_RIGHT);
        footerTable.addCell(c);

        footerTable.addCell(createFooterCell(new Chunk()));
        footerTable.writeSelectedRows(0, -1, document.getPageSize().getLeft() + document.leftMargin(),
                document.getPageSize().getBottom(document.bottomMargin()), writer.getDirectContentUnder());
        footerBottom = document.bottom() - footerTable.getTotalHeight();
    }
}

From source file:dbedit.actions.ExportPdfAction.java

License:Open Source License

/**
 * Print page numbers on right bottom corner
 * @param writer//  w  w  w  .j a v a  2 s  .  co m
 * @param document
 */
@Override
public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte cb = writer.getDirectContent();
    String text = String.format("Page %d of ", writer.getPageNumber());
    float textSize = BASE_FONT.getWidthPoint(text, 12);
    float textBase = document.bottom() - 20;
    cb.beginText();
    cb.setFontAndSize(BASE_FONT, 12);
    float adjust = BASE_FONT.getWidthPoint("000", 12);
    cb.setTextMatrix(document.right() - textSize - adjust, textBase);
    cb.showText(text);
    cb.endText();
    cb.addTemplate(pdfTemplate, document.right() - adjust, textBase);
}

From source file:eyeofthetiger.utils.PDFDossardGenerator.java

public void createPdf(List<Participant> participants, OutputStream out) throws IOException, DocumentException {
    sortParticipants(participants);//from  www .ja va2s . c  o m

    Document document = new Document(PageSize.A4.rotate());
    float margin = CentimeterToUserSpace(marginCm);
    document.setMargins(margin, margin, margin, margin);
    PdfWriter writer = PdfWriter.getInstance(document, out);
    document.open();
    PdfContentByte cb = writer.getDirectContent();

    PdfReader pdfBackgroundReader = null;
    PdfImportedPage backgroundPage = null;
    if (pdfBackground != null && (new File(pdfBackground)).exists() && (new File(pdfBackground)).isFile()) {
        pdfBackgroundReader = new PdfReader(pdfBackground);
        backgroundPage = writer.getImportedPage(pdfBackgroundReader, 1);
    }

    float documentTop = document.top();
    float documentBottom = document.bottom();
    float documentHeight = documentTop - documentBottom;
    float left = document.left();
    float right = document.right();
    float width = right - left;
    float height = documentTop - documentBottom;

    //cb.rectangle(left, documentBottom, width, documentHeight);
    //cb.stroke();

    boolean logoLeftExist = (new File(logoLeft)).exists() && (new File(logoLeft)).isFile();
    boolean logoRightExist = (new File(logoRight)).exists() && (new File(logoRight)).isFile();

    float imgLeftRight = left;
    float imgLeftBottom = documentTop;
    float imgRightLeft = right;
    float imgRighBottom = documentTop;
    Image imgLeft = null;
    Image imgRight = null;
    if (exportLogos) {
        if (logoLeftExist) {
            imgLeft = Image.getInstance(logoLeft);
            float h = imgLeft.getHeight();
            float w = imgLeft.getWidth();
            float nw = width * logoLeftWidth;
            float nh = (h / w) * nw;
            imgLeft.scaleAbsolute(nw, nh);
            //img.scaleAbsoluteHeight(img.getScaledWidth() / xyRatio);
            imgLeft.setAbsolutePosition(left, documentTop - imgLeft.getScaledHeight());
            //cb.addImage(img);   

            imgLeftRight = imgLeft.getAbsoluteX() + imgLeft.getScaledWidth();
            imgLeftBottom = imgLeft.getAbsoluteY();
        }

        if (logoRightExist) {
            imgRight = Image.getInstance(logoRight);
            float h = imgRight.getHeight();
            float w = imgRight.getWidth();
            float nw = width * logoRightWidth;
            float nh = (h / w) * nw;
            imgRight.scaleAbsolute(nw, nh);
            imgRight.setAbsolutePosition(right - imgRight.getScaledWidth(),
                    documentTop - imgRight.getScaledHeight());
            //cb.addImage(imgRight);
            imgRightLeft = imgRight.getAbsoluteX();
            imgRighBottom = imgRight.getAbsoluteY();
        }

    }

    float nameHeightPercent = 0.35f;
    float groupHeightPercent = 0.25f;

    float nameTop = documentTop;
    float nameBottom = nameTop;
    if (exportName) {
        nameBottom = nameTop - (documentHeight * nameHeightPercent);
    }
    float groupeTop = nameBottom;
    float groupeBottom = nameBottom;
    if (exportGroup) {
        groupeBottom = groupeTop - (documentHeight * groupHeightPercent);
    }
    float barcodeTop = groupeBottom;
    float barcodeBottom = documentBottom;

    ColumnText columnText;

    for (Participant participant : participants) {

        if (backgroundPage != null) {
            //cb.addTemplate(backgroundPage, 1f, 0, 0, 1, 0, 0); //TODO
            cb.addTemplate(backgroundPage, 0, 0);
        }

        float nameFontSize = 65f;
        float groupFontSize = 45f;
        float renseignementFontSize = 35f;

        if (imgLeft != null) {
            cb.addImage(imgLeft);
        }
        if (imgRight != null) {
            cb.addImage(imgRight);
        }

        if (exportName) {
            columnText = new ColumnText(cb);
            columnText.setAlignment(Rectangle.ALIGN_CENTER);

            if (imgLeftRight != -1 && imgLeftBottom != -1) {
                float[] leftBorder = null;
                if (imgLeftBottom < nameBottom) {
                    leftBorder = new float[] { imgLeftRight, nameTop, imgLeftRight, nameBottom, left,
                            nameBottom };
                } else {
                    leftBorder = new float[] { imgLeftRight, nameTop, imgLeftRight, imgLeftBottom, left,
                            imgLeftBottom, left, nameBottom };
                }

                float[] rightBorder = null;
                if (imgRighBottom < nameBottom) {
                    rightBorder = new float[] { imgRightLeft, nameTop, imgRightLeft, nameBottom, right,
                            nameBottom };
                } else {
                    rightBorder = new float[] { imgRightLeft, nameTop, imgRightLeft, imgRighBottom, right,
                            imgRighBottom, right, nameBottom };
                }

                columnText.setColumns(leftBorder, rightBorder);
            } else {
                columnText.setSimpleColumn(left, nameTop, right, nameBottom);
            }
            //cb.rectangle(left, nameBottom, width, (nameTop - nameBottom));
            //cb.stroke();

            columnText.setExtraParagraphSpace(0f);
            columnText.setAdjustFirstLine(false);
            columnText.setIndent(0);

            String txt = participant.getNom().toUpperCase() + " " + participant.getPrenom();

            float previousPos = columnText.getYLine();
            columnText.setLeading(nameFontSize);
            columnText.setText(createCleanPhrase(txt, nameFontSize, true));
            while (nameFontSize > 1 && ColumnText.hasMoreText(columnText.go(true))) {
                nameFontSize = nameFontSize - 0.5f;
                columnText.setLeading(nameFontSize);
                columnText.setText(createCleanPhrase(txt, nameFontSize, true));
                columnText.setYLine(previousPos);
            }

            columnText.setLeading(nameFontSize);
            columnText.setText(createCleanPhrase(txt, nameFontSize, true));
            columnText.setYLine(previousPos);
            columnText.go(false);

        }

        if (exportGroup) {
            columnText = new ColumnText(cb);
            columnText.setAlignment(Rectangle.ALIGN_CENTER);

            columnText.setSimpleColumn(document.left(), groupeTop, document.right(), groupeBottom);
            float groupeHeight = groupeTop - groupeBottom;
            //cb.rectangle(document.left(), groupeTop - groupeHeight, document.right() - document.left(), groupeHeight);
            //cb.stroke();

            columnText.setExtraParagraphSpace(0f);
            columnText.setAdjustFirstLine(false);
            columnText.setIndent(0);
            columnText.setFollowingIndent(0);

            String txt1 = participant.getGroupe();
            String txt2 = exportRenseignement ? "\n" + participant.getRenseignements() : null;

            float previousPos = columnText.getYLine();
            columnText.setText(null);
            columnText.setLeading(groupFontSize);
            columnText.addText(createCleanPhrase(txt1, groupFontSize, true));
            columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false));
            while (groupFontSize > 1 && ColumnText.hasMoreText(columnText.go(true))) {
                groupFontSize = groupFontSize - 0.5f;
                renseignementFontSize = renseignementFontSize - 0.5f;
                columnText.setText(null);
                columnText.setLeading(groupFontSize);
                columnText.addText(createCleanPhrase(txt1, groupFontSize, true));
                columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false));
                columnText.setYLine(previousPos);
            }

            columnText.setText(null);
            columnText.setLeading(groupFontSize);
            columnText.addText(createCleanPhrase(txt1, groupFontSize, true));
            columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false));
            columnText.setYLine(previousPos);
            columnText.go(false);
        }

        {
            columnText = new ColumnText(cb);

            float topMargin = 12f;
            columnText.setSimpleColumn(left, barcodeTop - topMargin, right, barcodeBottom);
            float barcodeHeight = (barcodeTop - topMargin) - barcodeBottom;
            //cb.rectangle(left, barcodeTop - barcodeHeight, width, barcodeHeight);
            //cb.stroke();

            columnText.setExtraParagraphSpace(0f);
            columnText.setAdjustFirstLine(false);
            columnText.setIndent(0);

            float previousPos = columnText.getYLine();
            columnText.setText(null);
            columnText.addElement(createCleanBarcode(cb, participant.getNumero(), width, barcodeHeight));
            columnText.go(false);
        }

        document.newPage();

    }

    document.close();

    if (pdfBackgroundReader != null) {
        pdfBackgroundReader.close();
    }
}