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:be.fedict.eid.tsl.Tsl2PdfExporter.java

License:Open Source License

protected void addItemRow(final String label, final Iterable<String> values, final PdfPTable table) {
    if (values != null) {
        boolean nonEmpty = false;
        final PdfPCell valueCell = new PdfPCell();
        valueCell.setBorder(0);/*ww  w. j  a v  a 2s . com*/
        for (String s : values) {
            valueCell.addElement(new Paragraph(s, valueFont));
            nonEmpty = true;
        }
        if (nonEmpty) {
            table.addCell(new Phrase(label, labelFont));
            table.addCell(valueCell);
        }
    }
}

From source file:beans.ManagedBeanProducto.java

License:Open Source License

public String CreatePdf() throws IOException, DocumentException {
    ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
    //System.out.println(" test: "+extContext);
    //System.out.println(" esta es la ruta" + extContext.getRealPath("//pdfs//"));
    // step 1//from   w w  w .ja  v a2s.co  m
    String ruta_pdfs = extContext.getRealPath("//pdfs//");
    Document document = new Document(PageSize.A4);
    document.setMargins(5, 5, 25, 25);
    document.setMarginMirroring(true);

    // step 2
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(ruta_pdfs + "//CB" + Producto.getIdProducto() + ".pdf"));
    // step 3
    document.open();
    // step 4
    PdfContentByte cb = writer.getDirectContent();

    Paragraph Titulo = new Paragraph(
            "PRODUCTO : " + Producto.getNombreProducto().substring(14).toUpperCase() + "\n\n");
    Titulo.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(Titulo);

    // EAN 13
    // document.add(new Paragraph("Barcode EAN.UCC-13"));
    BarcodeEAN codeEAN = new BarcodeEAN();

    codeEAN.setCode(CodigoBarrasFinal());
    String nombre_producto = "";
    if (Producto.getNombreProducto().length() >= 41) {
        nombre_producto = Producto.getNombreProducto().substring(14, 41);
    } else {
        nombre_producto = Producto.getNombreProducto().substring(14);
    }
    // document.add(new Paragraph(nombre_producto,new Font(Font.COURIER, 5, Font.NORMAL)));
    // document.add(codeEAN.createImageWithBarcode(cb,Color.BLUE , Color.BLUE));
    // codeEAN.setGuardBars(false);

    // document.add(new Paragraph(nombre_producto,new Font(Font.COURIER, 5, Font.NORMAL)));
    // codeEAN.setGuardBars(false);
    Image imagen = codeEAN.createImageWithBarcode(cb, null, null);
    imagen.scaleAbsolute(87, 45);
    //document.add(imagen);

    PdfPTable table = new PdfPTable(5);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    // table.setTotalWidth(1800);
    PdfPCell cell;
    Phrase nombre = new Phrase(nombre_producto.toUpperCase(),
            new Font(Font.COURIER, 5, Font.BOLD, Color.BLACK));

    cell = new PdfPCell();
    cell.addElement(nombre);
    //cell.addElement(new Chunk("\n"));
    cell.addElement(imagen);
    //cell.addElement(new Chunk("\n"));

    table.addCell(cell);
    //table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    table.addCell(cell);
    //table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    // EAN 8 "6987";
    // String inicio ="345";
    //  int intermedio =1000+Producto.getIdProducto();
    //  String fin ="0";
    // document.add(new Paragraph(Producto.getNombreProducto(),new Font(Font.COURIER, 4, Font.NORMAL)));
    // codeEAN.setCodeType(Barcode.EAN8);
    // codeEAN.setBarHeight(codeEAN.getSize() * 1.5f);
    // codeEAN.setCode(inicio.concat(intermedio+fin));
    // document.add(codeEAN.createImageWithBarcode(cb, null, null));
    document.close();

    return "codigo_barras_productos";
}

From source file:ca.sqlpower.architect.profile.output.ProfilePDFFormat.java

License:Open Source License

/**
 * @param widths The maximum width of each column's contents in
 * points.  THIS ARRAY WILL BE MODIFIED to the width of the widest
 * single word in the heading if it is wider than the existing
 * width value for that column.  Words are split using the default
 * settings for java.util.StringTokenizer.
 * @param headerTopNColumns reference to the null count/% inner table in the header
 * @param headerValueColumns reference to the unique count/% inner table in the header
 * @param headerLengthColumns reference to the length min/max/avg inner table in the header
 * @param headerUniqueColumns reference to the value min/max/avg inner table in the header
 * @param headerNullColumns reference to the top N Value/count inner table in the header
 * we will resert widths of these inner table after we have all rows
 */// w w  w  .j a v  a  2  s.co  m
private void addHeaderRow(TableProfileResult result, ProfileTableStructure profile, BaseFont bf,
        float titleFSize, float colHeadingFSize, float[] widths)
        throws DocumentException, IOException, SQLObjectException {

    int ncols = headings.length;

    Font titleFont = new Font(bf, titleFSize, Font.BOLD);
    Font colHeadingFont = new Font(bf, colHeadingFSize);
    PdfPTable table = profile.getMainTable();
    SQLTable sqlTable = result.getProfiledObject();

    //        TableProfileResult tProfile = (TableProfileResult) pm.getResult(sqlTable);
    PdfPTable infoTable = new PdfPTable(2);
    StringBuffer heading = new StringBuffer();
    heading.append("Connection: ").append(sqlTable.getParentDatabase().getName()).append("\n");
    heading.append("Table: ").append(SQLObjectUtils.toQualifiedName(sqlTable, SQLDatabase.class));
    if (result.getException() != null) {
        heading.append("\nProfiling Error");
        if (result.getException() != null) {
            heading.append(":\n").append(result.getException());
            StackTraceElement[] stackTrace = result.getException().getStackTrace();
            for (int i = 0; i < STACK_TRACE_LENGTH && i < stackTrace.length; i++) {
                StackTraceElement element = stackTrace[i];
                heading.append("\n   ").append(element.getFileName()).append(".").append(element.getClassName())
                        .append(".").append(element.getMethodName()).append("(").append(element.getLineNumber())
                        .append(")");
            }
            if (stackTrace.length > STACK_TRACE_LENGTH) {
                heading.append("\n   ... ").append(stackTrace.length).append(" more");
            }
        }
    } else {
        PdfPCell infoCell;

        infoCell = new PdfPCell(new Phrase("Row Count:", colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        infoTable.addCell(infoCell);

        infoCell = new PdfPCell(new Phrase(String.valueOf(result.getRowCount()), colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoTable.addCell(infoCell);

        infoCell = new PdfPCell(new Phrase("Create Date:", colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        infoTable.addCell(infoCell);

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        infoCell = new PdfPCell(new Phrase(df.format(new Date(result.getCreateStartTime())), colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoTable.addCell(infoCell);

        infoCell = new PdfPCell(new Phrase("Elapsed:", colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        infoTable.addCell(infoCell);

        infoCell = new PdfPCell(new Phrase(result.getTimeToCreate() + "ms", colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoTable.addCell(infoCell);
    }

    PdfPCell hcell = new PdfPCell(new Phrase(heading.toString(), titleFont));
    hcell.setColspan(ncols - 3);
    hcell.setBorder(Rectangle.NO_BORDER);
    hcell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    table.addCell(hcell);

    hcell = new PdfPCell(infoTable);
    hcell.setColspan(3);
    hcell.setBorder(Rectangle.NO_BORDER);
    table.addCell(hcell);

    if (sqlTable.getColumns().size() > 0) {

        int colNo = 0;
        // column name
        Phrase colTitle = new Phrase("Column Name", colHeadingFont);
        PdfPCell cell = new PdfPCell(colTitle);
        cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP);
        cell.setBorderWidth(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        // ensure column width is at least enough for widest word in heading
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        // date type
        colTitle = new Phrase("Data Type", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP);
        cell.setBorderWidth(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        // null count and %
        colTitle = new Phrase("NULL", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableNullColumn().addCell(cell);

        colTitle = new Phrase("#", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableNullColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("%", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableNullColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableNullColumn());
        cell.setColspan(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorderWidth(2);
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        table.addCell(cell);

        // unique count and %
        colTitle = new Phrase("Unique", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        profile.getInnerTableUniqueColumn().addCell(cell);

        colTitle = new Phrase("#", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableUniqueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("%", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableUniqueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableUniqueColumn());
        cell.setColspan(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        cell.setBorderWidth(2);
        table.addCell(cell);

        // length max/min/avg
        colTitle = new Phrase("Length", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        profile.getInnerTableLengthColumn().addCell(cell);

        colTitle = new Phrase("Min", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableLengthColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("Max", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableLengthColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("Avg", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableLengthColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableLengthColumn());
        cell.setColspan(3);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorderWidth(2);
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        table.addCell(cell);

        // value max/min/avg
        colTitle = new Phrase("Value", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        profile.getInnerTableValueColumn().addCell(cell);

        colTitle = new Phrase("Min", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableValueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("Max", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableValueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("Avg", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableValueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableValueColumn());
        cell.setColspan(3);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorderWidth(2);
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        table.addCell(cell);

        // top n
        colTitle = new Phrase("Top N", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        profile.getInnerTableTopNColumn().addCell(cell);

        colTitle = new Phrase("Values", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableTopNColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("#", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableTopNColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableTopNColumn());
        cell.setColspan(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorderWidth(2);
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        table.addCell(cell);

    } else {
        hcell = new PdfPCell(new Phrase("No Column Found in the table", titleFont));
        hcell.setColspan(ncols);
        hcell.setBorder(Rectangle.BOTTOM);
        hcell.setVerticalAlignment(Element.ALIGN_LEFT);
        table.addCell(hcell);
    }
    table.setHeaderRows(2);
}

From source file:ca.sqlpower.architect.profile.output.ProfilePDFFormat.java

License:Open Source License

private void addBodyRow(TableProfileResult tProfile, ColumnProfileResult result, DDLGenerator ddlg,
        PdfPTable table, BaseFont bf, Font f, float fsize, float[] widths)
        throws DocumentException, IOException, SQLObjectException, SQLException {

    SQLColumn col = result.getProfiledObject();

    int rowCount = -1;
    if (tProfile != null && tProfile.getException() == null) {
        rowCount = tProfile.getRowCount();
    }/*www  .  j  a v a 2  s  .com*/
    java.util.List<ColumnValueCount> topTen = null;

    boolean errorColumnProfiling = false;
    Exception columnException = null;
    if (result != null && result.getException() == null) {
        topTen = result.getValueCount();
    } else {
        errorColumnProfiling = true;
        if (result != null && result.getException() != null) {
            columnException = result.getException();
            logger.debug("Exception " + columnException + " on column " + col.getName());
        }
    }

    DecimalFormat pctFormat = new DecimalFormat("0%");

    DecimalFormat df = new DecimalFormat("#,##0.00");
    df.setMaximumFractionDigits(col.getScale());
    df.setMinimumFractionDigits(col.getScale());

    DecimalFormat adf = new DecimalFormat("#,##0.00");
    adf.setMaximumFractionDigits(Math.max(2, col.getScale()));
    adf.setMinimumFractionDigits(Math.max(2, col.getScale()));

    DecimalFormat aldf = new DecimalFormat("#,##0.0");
    aldf.setMaximumFractionDigits(1);
    aldf.setMinimumFractionDigits(0);

    boolean errorSpanRemaining = false;
    for (int colNo = 0; colNo < totalColumn; colNo++) {

        String contents;
        int alignment;

        if (headings[colNo].equalsIgnoreCase("table name")) {
            String fqTableName = SQLObjectUtils.toQualifiedName(col.getParent(), SQLDatabase.class);
            if (tProfile == null || tProfile.getException() != null) {
                contents = fqTableName + "\nProfiling Error:\n";
                if (tProfile != null && tProfile.getException() != null) {
                    contents += tProfile.getException();
                    errorSpanRemaining = true;
                }
            } else {
                contents = fqTableName;
            }
            alignment = Element.ALIGN_LEFT;
        } else if (headings[colNo].equalsIgnoreCase("row count")) {
            contents = String.valueOf(rowCount);
            alignment = Element.ALIGN_RIGHT;
        } else if (headings[colNo].equalsIgnoreCase("column name")) {
            contents = col.getName();
            alignment = Element.ALIGN_LEFT;
        } else if (headings[colNo].equalsIgnoreCase("data type")) {
            contents = ddlg.columnType(col);
            alignment = Element.ALIGN_LEFT;
        } else if (headings[colNo].equalsIgnoreCase("null count")) {

            if (errorColumnProfiling) {
                if (result == null) {
                    contents = "Column Profiling Not Found\n";
                } else {
                    contents = "Column Profiling Error:\n";
                    if (columnException != null) {
                        contents += columnException;
                        errorSpanRemaining = true;
                    }
                }
                alignment = Element.ALIGN_LEFT;
            } else {
                if (col.isDefinitelyNullable()) {
                    contents = String.valueOf(result.getNullCount());
                } else {
                    contents = "---";
                }
                alignment = Element.ALIGN_RIGHT;
            }
        } else if (headings[colNo].equalsIgnoreCase("% null")) {
            if (errorColumnProfiling) {
                continue;
            } else {
                if (col.isDefinitelyNullable()) {
                    if (rowCount <= 0) {
                        contents = "N/A";
                        alignment = Element.ALIGN_CENTER;
                    } else {
                        contents = pctFormat.format(result.getNullCount() / (double) rowCount);
                        alignment = Element.ALIGN_RIGHT;
                    }
                } else {
                    contents = "---";
                    alignment = Element.ALIGN_CENTER;
                }
            }
        } else if (headings[colNo].equalsIgnoreCase("Unique Count")) {
            if (!errorColumnProfiling) {
                contents = String.valueOf(result.getDistinctValueCount());
                alignment = Element.ALIGN_RIGHT;
            } else {
                continue;
            }
        } else if (headings[colNo].equalsIgnoreCase("% unique")) {
            if (!errorColumnProfiling) {
                if (rowCount == 0) {
                    contents = "N/A";
                    alignment = Element.ALIGN_CENTER;
                } else {
                    contents = pctFormat.format(result.getDistinctValueCount() / (double) rowCount);
                    alignment = Element.ALIGN_RIGHT;
                }
            } else {
                continue;
            }
        } else if (headings[colNo].equalsIgnoreCase("Min Length")) {
            if (!errorColumnProfiling) {
                contents = String.valueOf(result.getMinLength());
                alignment = Element.ALIGN_RIGHT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("Max Length")) {
            if (!errorColumnProfiling) {
                contents = String.valueOf(result.getMaxLength());
                alignment = Element.ALIGN_RIGHT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("avg Length")) {
            if (!errorColumnProfiling) {
                contents = aldf.format(result.getAvgLength());
                alignment = Element.ALIGN_RIGHT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("Min value")) {
            if (!errorColumnProfiling) {
                if (result.getMinValue() == null) {
                    alignment = Element.ALIGN_CENTER;
                    contents = "";
                } else if (result.getMinValue() instanceof Number) {
                    alignment = Element.ALIGN_RIGHT;
                    contents = df.format((Number) result.getMinValue());
                } else {
                    alignment = Element.ALIGN_LEFT;
                    contents = String.valueOf(result.getMinValue());
                }
                alignment = Element.ALIGN_LEFT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("Max value")) {
            if (!errorColumnProfiling) {
                if (result.getMaxValue() == null) {
                    alignment = Element.ALIGN_CENTER;
                    contents = "";
                } else if (result.getMaxValue() instanceof Number) {
                    alignment = Element.ALIGN_RIGHT;
                    contents = df.format((Number) result.getMaxValue());
                } else {
                    alignment = Element.ALIGN_LEFT;
                    contents = String.valueOf(result.getMaxValue());
                }
                alignment = Element.ALIGN_LEFT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("avg value")) {
            if (!errorColumnProfiling) {
                if (result.getAvgValue() == null) {
                    alignment = Element.ALIGN_CENTER;
                    contents = "";
                } else if (result.getAvgValue() instanceof Number) {
                    alignment = Element.ALIGN_RIGHT;
                    contents = adf.format((Number) result.getAvgValue());
                } else {
                    alignment = Element.ALIGN_LEFT;
                    contents = String.valueOf(result.getAvgValue());
                }
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("Top N Values")) {
            if (!errorColumnProfiling && topTen != null) {
                StringBuffer sb = new StringBuffer();
                for (ColumnValueCount cvc : topTen) {
                    sb.append(cvc.getValue()).append("\n");
                }
                contents = sb.toString();
                alignment = Element.ALIGN_LEFT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else if (headings[colNo].equalsIgnoreCase("Count")) {
            if (!errorColumnProfiling) {
                StringBuffer sb = new StringBuffer();
                for (ColumnValueCount cvc : topTen) {
                    sb.append(cvc.getCount()).append("\n");
                }
                contents = sb.toString();
                alignment = Element.ALIGN_RIGHT;
            } else {
                contents = "";
                alignment = Element.ALIGN_LEFT;
            }
        } else {
            throw new IllegalStateException("I don't know about column " + colNo);
        }

        StringBuffer truncContents = new StringBuffer(contents.length());

        // update column width to reflect the widest cell
        for (String contentLine : contents.split("\n")) {
            String newLine;
            if (truncateLength >= 0 && !errorSpanRemaining) {
                if (bf.getWidthPoint(contentLine, fsize) < truncateLength) {
                    newLine = contentLine + "\n";
                } else {
                    double currentLength = bf.getWidthPoint("...", fsize);
                    int stringPosition = 0;
                    for (; stringPosition < contentLine.length(); stringPosition++) {
                        if (currentLength > truncateLength) {
                            break;
                        }
                        currentLength = bf.getWidthPoint(contentLine.substring(0, stringPosition) + "...",
                                fsize);
                        stringPosition++;
                    }
                    newLine = contentLine.substring(0, stringPosition - 1) + "...\n";
                }
            } else {
                newLine = contentLine + "\n";
            }
            truncContents.append(newLine);
            if (!errorSpanRemaining) {
                widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(newLine, fsize));
                logger.debug("width is now " + widths[colNo] + " for column " + colNo);
            }
        }

        PdfPCell cell;
        if (headings[colNo].equalsIgnoreCase("Top N Values") || headings[colNo].equalsIgnoreCase("Count")) {
            cell = new PdfPCell(new Paragraph(truncContents.toString(), f));
            cell.setNoWrap(true);
        } else if (headings[colNo].equalsIgnoreCase("null count") && errorColumnProfiling) {
            cell = new PdfPCell(new Paragraph(truncContents.toString(), f));
            cell.setColspan(4);
        } else {
            Phrase phr = new Phrase(truncContents.toString(), f);
            cell = new PdfPCell(phr);

        }
        //            cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(alignment);
        if (errorSpanRemaining) {
            cell.setColspan(totalColumn - colNo);
        }
        table.addCell(cell);
        if (errorSpanRemaining) {
            break;
        }
    }
}

From source file:ch.gpb.elexis.kgexporter.pdf.PdfHandler.java

License:Open Source License

public static PdfPTable createTable2(LinkedList<String[]> laborBlatt) throws DocumentException, IOException {
    int noOfCols = laborBlatt.get(0)[0].length();
    PdfPTable table = new PdfPTable(noOfCols);

    float[] colWidths = new float[noOfCols];
    colWidths[0] = 200f;//  w w  w .  jav a2s.  c o  m
    for (int i = 1; i < colWidths.length; i++) {
        colWidths[i] = 40f;
    }

    table.setTotalWidth(colWidths);
    table.setLockedWidth(true);

    // the cell object
    PdfPCell cell;

    for (String[] strings : laborBlatt) {

        for (int i = 0; i < strings.length; i++) {
            System.out.print(i + ":" + strings[i]);
            cell = new PdfPCell(new Phrase(strings[i], fontTimesSmall));

            cell.setUseBorderPadding(true);
            //
            // Setting cell's border width and color
            //
            cell.setBorderWidth(0.5f);

            table.addCell(cell);

        }
        //System.out.println("----------");
        //System.out.println();
    }

    // we add a cell with colspan 3
    return table;
}

From source file:classroom.filmfestival_c.Movies16.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {

    // step 1//  ww w .ja v  a2s.  co m
    Document document = new Document();
    try {
        // step 2
        OutputStream os = new FileOutputStream(RESULT);
        PdfWriter.getInstance(document, os);
        // step 3
        document.open();
        // step 4
        PdfPTable table;
        PdfPCell cell;
        Chunk imdb;

        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();
        java.util.List<FestivalScreening> screenings;

        for (Date day : days) {
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(day);
            if (gc.get(GregorianCalendar.YEAR) != YEAR)
                continue;

            table = new PdfPTable(new float[] { 7, 1, 2, 1 });
            cell = new PdfPCell(new Phrase(day.toString(), NORMALWHITE));
            cell.setBackgroundColor(BLACK);
            cell.setColspan(4);
            table.addCell(cell);

            q = session.createQuery("from FestivalScreening where id.day=? order by id.time, id.place");
            q.setDate(0, day);
            screenings = q.list();
            for (FestivalScreening screening : screenings) {
                table.addCell(screening.getFilmTitle().getTitle());
                table.addCell(screening.getId().getPlace().toString());
                cell = new PdfPCell(new Phrase(screening.getId().getTime().toString()));
                if (screening.getPress() == 1) {
                    cell.setBackgroundColor(SILVER);
                }
                table.addCell(cell);
                if (screening.getFilmTitle().getImdb().startsWith("?")) {
                    table.addCell("");
                } else {
                    imdb = new Chunk("imdb");
                    imdb.setAnchor("http://imdb.com/title/tt" + screening.getFilmTitle().getImdb());
                    table.addCell(new Phrase(imdb));
                }
            }

            document.add(table);
        }

        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_c.Movies17.java

@SuppressWarnings("unchecked")
protected static Element getTable(Query q, Date date) throws DocumentException {
    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100f);/*from   w w  w .j a v  a  2  s  .  com*/

    PdfPCell cell = new PdfPCell(new Phrase(date.toString(), NORMALWHITE));
    cell.setBackgroundColor(BLACK);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    q.setDate(0, date);
    java.util.List<FestivalScreening> screenings = q.list();
    for (FestivalScreening screening : screenings) {
        addScreening(table, screening);
    }
    return table;
}

From source file:classroom.filmfestival_c.Movies17.java

protected static Element fullTitle(FestivalScreening screening) throws DocumentException {
    FilmTitle movie = screening.getFilmTitle();
    // a table with 3 cells
    PdfPTable table = new PdfPTable(3);
    table.setWidths(INNER);/* www  .jav  a  2  s  .  c  om*/
    table.setWidthPercentage(100);

    // the title(s)
    Paragraph p = new Paragraph();
    p.add(new Phrase(movie.getTitle(), BOLD));
    p.setLeading(16);
    // maybe an alternative title
    if (movie.getATitle().trim().length() > 0) {
        p.add(new Phrase(" (" + movie.getATitle() + ")"));
    }
    PdfPCell cell = new PdfPCell();
    cell.addElement(p);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setUseAscender(true);
    cell.setUseDescender(true);
    table.addCell(cell);

    // eXploreZone?
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    if (isExploreZone(movie)) {
        cell.setBackgroundColor(WHITE);
        cell.setUseAscender(true);
        cell.setUseDescender(true);
        cell.addElement(new Paragraph("eXplore"));
    }
    table.addCell(cell);

    // Duration / shortfilm
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setBackgroundColor(WHITE);
    cell.setUseAscender(true);
    cell.setUseDescender(true);
    StringBuffer buf = new StringBuffer();
    buf.append(movie.getDuration());
    buf.append('\'');
    if (getExtra(screening) > 0) {
        buf.append(" + KF");
        buf.append(getExtra(screening));
        buf.append('\'');
    }
    p = new Paragraph(buf.toString());
    p.setAlignment(Element.ALIGN_CENTER);
    cell.addElement(p);
    table.addCell(cell);
    return table;
}

From source file:classroom.filmfestival_c.Movies19.java

protected static void drawMovie(PdfWriter writer, FestivalScreening screening, List<String> places,
        float minute, float left, float top, float row_height) throws DocumentException {
    FilmTitle movie = screening.getFilmTitle();
    // defining the rectangle
    int place = places.indexOf(screening.getId().getPlace());
    float llx, urx, lly, ury;
    llx = left + minute * getMinutesAfter930(screening);
    urx = llx + minute * (screening.getShortfilm() + movie.getDuration());
    ury = top - place * row_height;/*from  w w  w.ja v  a 2 s.c  om*/
    lly = top - ((place + 1) * row_height);

    // FOREGROUND
    PdfContentByte foreground = writer.getDirectContent();

    // rectangle
    foreground.setColorStroke(BLACK);
    foreground.setLineWidth(1);
    foreground.moveTo(urx, lly);
    foreground.lineTo(llx, lly);
    foreground.lineTo(llx, ury);
    foreground.lineTo(urx, ury);
    foreground.closePathStroke();
    // title
    ColumnText ct = new ColumnText(foreground);
    ct.setSimpleColumn(new Phrase(movie.getTitle(), SMALLEST), llx, lly, urx, ury, 14, Element.ALIGN_CENTER);
    ct.go();

    // BACKGROUND
    PdfContentByte background = writer.getDirectContentUnder();

    // draw background
    background.setColorFill(getColor(movie));
    background.moveTo(urx, lly);
    background.lineTo(llx, lly);
    background.lineTo(llx, ury);
    background.lineTo(urx, ury);
    background.fill();

    // draw a white P for press screenings
    if (screening.getPress() == 1) {
        background.saveState();
        background.beginText();
        background.setFontAndSize(FONT, 24);
        background.setColorFill(WHITE);
        background.showTextAligned(Element.ALIGN_CENTER, "P", (llx + urx) / 2f, (lly + ury) / 2f - 12, 0);
        background.endText();
        background.restoreState();
    }

    // draw shortfilm
    background.setColorStroke(WHITE);
    if (screening.getShortfilm() > 0) {
        background.moveTo(llx + (minute * screening.getShortfilm()), lly);
        background.lineTo(llx + (minute * screening.getShortfilm()), ury);
        background.stroke();
    }
}

From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java

License:Open Source License

public static void addHeader(PdfWriter writer, String header) {
    class MyFooter extends PdfPageEventHelper {
        com.lowagie.text.Font ffont;

        @Override//from  w ww .ja v  a 2  s.com
        public void onEndPage(PdfWriter writer, Document document) {
            try {
                ffont = new com.lowagie.text.Font(
                        BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED), 6f,
                        com.lowagie.text.Font.ITALIC);
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }

            String date = FormatterUtils.formatDateTime(new Date());
            PdfContentByte cb = writer.getDirectContent();
            ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase(header, ffont), document.left(),
                    document.top() + 5, 0);
            ColumnText.showTextAligned(cb, Element.ALIGN_CENTER,
                    new Phrase("Page " + writer.getCurrentPageNumber(), ffont),
                    (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() - 5, 0);
            ColumnText.showTextAligned(cb, Element.ALIGN_RIGHT, new Phrase(date, ffont), document.right(),
                    document.bottom() - 5, 0);
        }
    }
    writer.setPageEvent(new MyFooter());
}