Example usage for com.lowagie.text Phrase Phrase

List of usage examples for com.lowagie.text Phrase Phrase

Introduction

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

Prototype

public Phrase(float leading, String string) 

Source Link

Document

Constructs a Phrase with a certain leading and a certain String.

Usage

From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java

License:Apache License

/**
 * Creates the pdf headers./*from   ww  w  .  ja v a 2 s.c o  m*/
 *
 * @param pdfPTable
 *            the pdf P table
 * @param font
 *            the font
 * @throws DocumentException
 *             the document exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public void createPdfHeaders(final PdfPTable pdfPTable, Font font) throws DocumentException, IOException {
    font = getFont();
    final float width = pdfPTable.getWidthPercentage();
    final int headerWidth = (int) width;
    final PdfPCell headersCells = new PdfPCell(new Phrase(getHeader(), font));
    headersCells.setHorizontalAlignment(Element.ALIGN_CENTER);
    headersCells.setColspan(headerWidth);
    headersCells.setUseDescender(true);
    headersCells.setBorder(0);
    pdfPTable.addCell(headersCells);
    for (int i = 0; i < this.model.getColumnCount(); i++) {
        if (this.model.isVisible(i)) {
            final PdfPCell cell = new PdfPCell(new Phrase(Lables.get(this.model.getActualColumnName(i)), font));
            cell.setRotation(getRotationDegree());
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            pdfPTable.addCell(cell);
        }
    }
    // Please explain
    pdfPTable.setHeaderRows(3);
    createPdfFooter(pdfPTable, font);

}

From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java

License:Apache License

/**
 * Load data table./*from w  w w.j a va  2  s  .  c  o  m*/
 *
 * @param pdfPTable
 *            the pdf P table
 * @param font
 *            the font
 * @throws DocumentException
 *             the document exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public void loadDataTable(final PdfPTable pdfPTable, Font font) throws DocumentException, IOException {
    font = getFont();
    for (int row = 0; row < this.model.getRowCount(); row++) {
        for (int column = 0; column < this.model.getColumnCount(); column++) {
            if (this.model.isVisible(column)) {
                final PdfPCell cell = new PdfPCell(
                        new Phrase((String) this.model.getValueAt(row, column), font));
                cell.setNoWrap(true);
                cell.setRunDirection(getRunDirection());
                // TODO : make the alignment according to the colunm
                // datatype
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                pdfPTable.addCell(cell);
            }
        }
    }
}

From source file:com.jk.framework.pdf.JKPDFCell.java

License:Apache License

/**
 * Instantiates a new JKPDF cell.// w w  w.j  av a  2s.  c o  m
 *
 * @param text
 *            the text
 * @param fontSize
 *            the font size
 * @param colSpan
 *            the col span
 * @param hAlignment
 *            the h alignment
 * @param fontStyle
 *            the font style
 * @param fixedHeight
 *            the fixed height
 * @param getLable
 *            the get lable
 * @throws DocumentException
 *             the document exception
 */
public JKPDFCell(String text, final int fontSize, final int colSpan, final int hAlignment,
        final boolean fontStyle, final int fixedHeight, final boolean getLable) throws DocumentException {
    setColspan(colSpan);
    if (getLable) {
        text = Lables.get(text);
    }
    setPhrase(new Phrase(text, PDFUtil.createFont(fontSize, fontStyle)));
    setHorizontalAlignment(hAlignment);
    setVerticalAlignment(ALIGN_MIDDLE);
    setFixedHeight(fixedHeight);
}

From source file:com.kahlon.guard.controller.DocumentManager.java

/**
 *
 * @param document/* w  w w .j  a v  a2  s  .  c  om*/
 */
public void preProcessPDF(Object document) {
    try {

        BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", false);

        Document pdf = (Document) document;
        pdf.setPageSize(PageSize.A4);
        pdf.setMargins(5f, 5f, 10f, 5f);

        // headers and footers must be added before the document is opened
        HeaderFooter footer = new HeaderFooter(new Phrase("page: ", new Font(bf_courier)), true);
        footer.setBorder(Rectangle.NO_BORDER);
        footer.setAlignment(Element.ALIGN_CENTER);
        pdf.setFooter(footer);

        //            HeaderFooter header = new HeaderFooter(
        //                        new Phrase("This is a header without a page number", new Font(bf_courier)), false);
        //            header.setAlignment(Element.ALIGN_CENTER);
        //            pdf.setHeader(header);

        pdf.open();

        String logoPath = "/resources/image/logo.png";
        ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
        String logo = servletContext.getRealPath(logoPath);

        pdf.add(Image.getInstance(logo));

        Person person = context.getSelectedPerson().getDisplayPerson();

        String name = FacesMessageUtil.getMessage("person.name") + " : " + person.getName();
        String age = FacesMessageUtil.getMessage("person.age") + " : " + Integer.toString(person.getAge());
        String gender = FacesMessageUtil.getMessage("person.gender") + " : "
                + person.getGender().getDescription();
        String race = FacesMessageUtil.getMessage("person.ethnicity") + " : "
                + person.getEthnicity().getDescription();

        Person rootPerson = person.getRootPerson();
        PersonImage imgp = imageService.getLastestPersonImage(rootPerson.getId());
        Image imgb = Image.getInstance(imgp.getContent());
        imgb.scaleToFit(100, 120);

        PdfPTable headerTable = new PdfPTable(2);

        PdfPTable personTable = new PdfPTable(1);
        personTable.setWidthPercentage(100);
        PdfPCell cell;

        cell = new PdfPCell(new Phrase(name));
        cell.setBorder(Rectangle.NO_BORDER);
        personTable.addCell(cell);

        cell = new PdfPCell(new Phrase(age));
        cell.setBorder(Rectangle.NO_BORDER);
        personTable.addCell(cell);

        cell = new PdfPCell(new Phrase(gender));
        cell.setBorder(Rectangle.NO_BORDER);
        personTable.addCell(cell);

        cell = new PdfPCell(new Phrase(race));
        cell.setBorder(Rectangle.NO_BORDER);
        personTable.addCell(cell);

        BarcodePDF417 pdf417 = new BarcodePDF417();
        pdf417.setText(Integer.toString(person.getId()));
        Image img = pdf417.getImage();
        img.scalePercent(150, 60 * pdf417.getYHeight());
        cell = new PdfPCell(img);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(15);
        personTable.addCell(cell);

        cell.addElement(personTable);
        headerTable.addCell(cell);

        cell = new PdfPCell(imgb);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(Rectangle.NO_BORDER);
        headerTable.addCell(cell);

        headerTable.setSpacingAfter(15);
        pdf.add(headerTable);

        LineSeparator lineSeparator = new LineSeparator();
        lineSeparator.setPercentage(82);
        pdf.add(lineSeparator);
        Paragraph space = new Paragraph();
        space.add("");
        space.setSpacingAfter(15);
        pdf.add(space);

    } catch (IOException e) {
        logger.log(Level.INFO, e.getMessage());
    } catch (BadElementException e) {
        logger.log(Level.INFO, e.getMessage());
    } catch (DocumentException e) {
        logger.log(Level.INFO, e.getMessage());
    } catch (Exception e) {
        logger.log(Level.INFO, e.getMessage());
    }

}

From source file:com.khs.report.writer.ReportPDFWriter.java

License:Apache License

private void addDetail(String[] data) throws DocumentException {

    for (String value : data) {
        PdfPCell c1 = new PdfPCell(new Phrase(value(value), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setHorizontalAlignment(alignment(value));
        setCellPadding(c1);/*from   w ww  .j  a  v a 2s  . c  o  m*/
        detailTable.addCell(c1);
    }

}

From source file:com.khs.report.writer.ReportPDFWriter.java

License:Apache License

private void addSubtotal(String[] data) throws DocumentException {

    // add dashed line...
    for (String value : data) {

        String v = null;/*from  ww w.j a va2s  .c o  m*/
        String rawValue = value(value);
        if (StringUtils.isNotEmpty(rawValue)) {
            v = line(rawValue, SINGLE_LINE);
        }

        PdfPCell c1 = new PdfPCell(new Phrase(v, font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setHorizontalAlignment(alignment(value));
        setCellPadding(c1);
        detailTable.addCell(c1);
    }

    // add totals....
    for (String value : data) {
        PdfPCell c1 = new PdfPCell(new Phrase(value(value), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setHorizontalAlignment(alignment(value));
        setCellPadding(c1);
        detailTable.addCell(c1);
    }

    // add blank line....
    for (String value : data) {
        PdfPCell c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        setCellPadding(c1);
        detailTable.addCell(c1);
    }

}

From source file:com.khs.report.writer.ReportPDFWriter.java

License:Apache License

private void addTotal(String[] data) throws DocumentException {

    // add dashed line...
    for (String value : data) {

        String v = null;//www . ja  va2  s . co  m
        String rawValue = value(value);
        if (StringUtils.isNotEmpty(rawValue)) {
            v = line(rawValue, SINGLE_LINE);
        }

        PdfPCell c1 = new PdfPCell(new Phrase(v, font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setHorizontalAlignment(alignment(value));
        setCellPadding(c1);
        detailTable.addCell(c1);
    }

    // add totals....
    for (String value : data) {
        PdfPCell c1 = new PdfPCell(new Phrase(value(value), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setHorizontalAlignment(alignment(value));
        setCellPadding(c1);
        detailTable.addCell(c1);
    }

    // add blank line....

    for (String value : data) {

        String v = null;
        String rawValue = value(value);
        if (StringUtils.isNotEmpty(rawValue)) {
            v = line(rawValue, DOUBLE_LINE);
        }

        PdfPCell c1 = new PdfPCell(new Phrase(v, font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setHorizontalAlignment(alignment(value));
        setCellPadding(c1);
        detailTable.addCell(c1);
    }

}

From source file:com.khs.report.writer.ReportPDFWriter.java

License:Apache License

private void createColHeadings(String[] cols) throws DocumentException {

    createTable(cols.length);/*from   www .jav  a  2s. c  om*/
    for (String col : cols) {
        PdfPCell c1 = new PdfPCell(new Phrase(value(col), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setHorizontalAlignment(alignment(col));
        setCellPadding(c1);
        c1.setPaddingBottom(5);
        detailTable.addCell(c1);
    }

}

From source file:com.khs.report.writer.ReportPDFWriter.java

License:Apache License

private void createFootings(String footing) throws DocumentException {
    String[] cols = footing.split(ReportProcessor.ALIGN_DELIMITER, 3);
    float[] colSizes = new float[] { 25, 50, 25 };

    footerTable = new PdfPTable(colSizes);
    footerTable.setWidthPercentage(getHeadingWidth());

    int count = 0;
    for (String c : cols) {
        PdfPCell c1 = new PdfPCell(new Phrase(value(c), font));

        c1.setBorder(Rectangle.NO_BORDER);
        int alignment = Element.ALIGN_CENTER;
        if (count == 0) {
            alignment = Element.ALIGN_LEFT;
        } else if (count == 2) {
            alignment = Element.ALIGN_RIGHT;
        }/*  w w w. j a v a 2 s  . co  m*/
        c1.setHorizontalAlignment(alignment);
        setCellPadding(c1);
        footerTable.addCell(c1);
        count++;
    }
}

From source file:com.khs.report.writer.ReportPDFWriter.java

License:Apache License

private void createHeading(String heading) throws DocumentException {

    String[] cols = heading.split(ReportProcessor.ALIGN_DELIMITER, 3);
    PdfPTable table = new PdfPTable(cols.length);
    table.setWidthPercentage(getHeadingWidth());

    int count = 0;
    for (String c : cols) {
        PdfPCell c1 = new PdfPCell(new Phrase(value(c), font));

        c1.setBorder(Rectangle.NO_BORDER);
        int alignment = Element.ALIGN_CENTER;
        if (count == 0) {
            alignment = Element.ALIGN_LEFT;
        } else if (count == 2) {
            alignment = Element.ALIGN_RIGHT;
        }// w  ww  .  j av a2  s  .c o  m
        c1.setHorizontalAlignment(alignment);
        setCellPadding(c1);
        table.addCell(c1);
        count++;
    }
    document.add(table);

}