Example usage for com.itextpdf.text.pdf PdfPCell setBorderColorBottom

List of usage examples for com.itextpdf.text.pdf PdfPCell setBorderColorBottom

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPCell setBorderColorBottom.

Prototype

public void setBorderColorBottom(final BaseColor borderColorBottom) 

Source Link

Document

Sets the color of the bottom border.

Usage

From source file:es.clinica.veterinaria.albaranes.AlbaranPdf.java

public PdfPTable createTable() throws DocumentException {
    // a table with three columns
    int iva = 0, iva2 = 0;
    DecimalFormat df = new DecimalFormat("0.00");
    PdfPTable table = new PdfPTable(5);
    table.setTotalWidth(new float[] { 55, 150, 200, 70, 70 });
    table.setLockedWidth(true);//from   w  w  w .java2  s .co  m

    // the cell object
    // we add a cell with colspan 3
    PdfPCell cell = new PdfPCell(new Phrase("CANT."));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("CONCEPTO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("DESCRIPCIN"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("PRECIO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("IMPORTE"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    HashSet<VentaLinea> listVenta = getVenta().getVenta_lineas();

    for (VentaLinea vlinea : listVenta) {
        if (vlinea.getTipo() == 1) {
            if (vlinea.getProducto().getIva() != null) {
                iva2 = vlinea.getProducto().getIva().getValor();
                //                    System.out.println("IVA: " +iva2);
            }
        } else if (vlinea.getTipo() == 2) {
            if (vlinea.getServicio().getIva() != null) {
                iva2 = vlinea.getServicio().getIva().getValor();
                //                    System.out.println("IVA: " +iva2);
            }
        }

        //Para hacer el calculo nos vamos a quedar con el IVA mayor
        if (iva < iva2) {
            iva = iva2;
        }

        cell = new PdfPCell(new Phrase(vlinea.getCantidad() + "", small));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPaddingBottom(5);
        table.addCell(cell);

        table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small)));

        String descripcion = vlinea.getDescripcion();
        if (descripcion == null || "null".equals(descripcion)) {
            table.addCell(new PdfPCell(new Phrase(" ", small)));
            //                System.out.println("null:" + descripcion);
        } else {
            table.addCell(new PdfPCell(new Phrase(descripcion, small)));
            //                System.out.println("!null:" + descripcion);
        }

        cell = new PdfPCell(new Phrase(df.format(vlinea.getPvp()) + " ", small));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setPaddingBottom(5);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(df.format(vlinea.getPreciototalNoIVA()) + " ", small));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setPaddingBottom(5);
        table.addCell(cell);
    }

    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("SUMA"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(venta.getCostesinIva()) + " "));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* IVA */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    //        float costetotal = (float) (venta.getCoste() * (1+(iva*0.01)));

    cell = new PdfPCell(new Phrase("IVA " + iva + "%"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(venta.getIvas()) + " "));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* COSTE TOTAL */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("TOTAL"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(venta.getCoste()) + " "));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    return table;
}

From source file:es.clinica.veterinaria.facturas.FacturaPdf.java

public PdfPTable createTable() throws DocumentException {
    // a table with three columns
    int iva = 0, iva2 = 0;
    DecimalFormat df = new DecimalFormat("0.00");
    PdfPTable table = new PdfPTable(6);
    table.setTotalWidth(new float[] { 50, 65, 150, 150, 65, 70 });
    table.setLockedWidth(true);/*from ww  w.j  a v a 2 s.c  o  m*/

    // the cell object
    // we add a cell with colspan 3
    PdfPCell cell = new PdfPCell(new Phrase("CANT."));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("FECHA"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("CONCEPTO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("DESCRIPCIN"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("PRECIO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("IMPORTE"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    HashSet<Venta> ventas = this.getFactura().getVentas();
    for (Venta venta : ventas) {
        HashSet<VentaLinea> listVenta = venta.getVenta_lineas();

        for (VentaLinea vlinea : listVenta) {
            if (vlinea.getTipo() == 1) {
                if (vlinea.getProducto().getIva() != null) {
                    iva2 = vlinea.getProducto().getIva().getValor();
                    //                    System.out.println("IVA: " +iva2);
                }
            } else if (vlinea.getTipo() == 2) {
                if (vlinea.getServicio().getIva() != null) {
                    iva2 = vlinea.getServicio().getIva().getValor();
                    //                    System.out.println("IVA: " +iva2);
                }
            }

            //Para hacer el calculo nos vamos a quedar con el IVA mayor
            if (iva < iva2) {
                iva = iva2;
            }

            cell = new PdfPCell(new Phrase(vlinea.getCantidad() + "", small));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setPaddingBottom(5);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(new SimpleDateFormat("dd-MM-yyyy").format(vlinea.getFecha()), small));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setPaddingBottom(5);
            table.addCell(cell);

            if (vlinea.getTipo() == 2) { //Servicio
                table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small)));

                String descripcion = vlinea.getDescripcion();
                if (descripcion == null || "null".equals(descripcion)) {
                    table.addCell(new PdfPCell(new Phrase(" ", small)));
                    //                System.out.println("null:" + descripcion);
                } else {
                    table.addCell(new PdfPCell(new Phrase(descripcion, small)));
                    //                System.out.println("!null:" + descripcion);
                }
            } else if (vlinea.getTipo() == 1) { //Producto
                //Si el producto es Tratamiento
                if (vlinea.getProducto().getFamilia().isTratamiento()) {
                    table.addCell(new PdfPCell(new Phrase("Tratamiento", small)));
                    table.addCell(new PdfPCell(new Phrase("", small)));
                } else {

                    table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small)));

                    String descripcion = vlinea.getDescripcion();
                    if (descripcion == null || "null".equals(descripcion)) {
                        table.addCell(new PdfPCell(new Phrase(" ", small)));
                        //                System.out.println("null:" + descripcion);
                    } else {
                        table.addCell(new PdfPCell(new Phrase(descripcion, small)));
                        //                System.out.println("!null:" + descripcion);
                    }
                }
            }
            cell = new PdfPCell(new Phrase(df.format(vlinea.getPvp()) + " ", small));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setPaddingBottom(5);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(df.format(vlinea.getPreciototalNoIVA()) + " ", small));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setPaddingBottom(5);
            table.addCell(cell);
        }
    }

    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("SUMA"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(factura.getCoste()) + " ", smallBold));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* IVA */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    float costetotal = (float) (factura.getCostetotal());

    cell = new PdfPCell(new Phrase("IVA " + iva + "%"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(factura.getIvas()) + " ", smallBold));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* COSTE TOTAL */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("TOTAL"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(costetotal) + " ", smallBold));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    return table;
}

From source file:femr.ui.controllers.PDFController.java

License:Open Source License

/**
 * Builds the page header - Title and Empty cell (for border)
 *
 * @return PdfPTable the itext table to add to the document
 *//*w  ww.  j av  a2  s. co m*/
public PdfPTable createHeaderTable() {

    PdfPTable table = new PdfPTable(2);
    table.setSpacingAfter(10);
    table.setWidthPercentage(100);

    Paragraph title = new Paragraph("Medical Record", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
    PdfPCell cell = new PdfPCell(title);
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderWidthBottom(1);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    //Paragraph encounterId = new Paragraph("Encounter ID: " + patientEncounter.getId(), new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
    cell = new PdfPCell(table.getDefaultCell());
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderWidthBottom(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    return table;
}

From source file:femr.ui.controllers.PDFController.java

License:Open Source License

/**
 * Builds the Header Cell used for every section of the document
 *
 * @param title the title for the cell// www .ja  va  2  s  .c  o  m
 * @param colspan the number of columns in the table it will be added to
 * @return a formatted PdfPCell ready to insert into a PdfPTable
 */
private PdfPCell getDefaultHeaderCell(String title, int colspan) {

    PdfPCell cell = new PdfPCell();
    Paragraph titleParagraph = new Paragraph(title,
            new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK));
    cell.addElement(titleParagraph);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setColspan(colspan);
    cell.setBorderColorBottom(BaseColor.DARK_GRAY);
    cell.setBorderWidthBottom(1);
    cell.setPaddingBottom(5);

    return cell;
}

From source file:fll.web.report.FinalComputedScores.java

License:Open Source License

@SuppressFBWarnings(value = {
        "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING" }, justification = "Category name determines table name")
private void writeScores(final Connection connection, final ScoreCategory[] subjectiveCategories,
        final double[] weights, final float[] relativeWidths, final String awardGroup,
        final WinnerType winnerCriteria, final Tournament tournament, final PdfPTable divTable,
        final Set<Integer> bestTeams) throws SQLException {

    final Map<ScoreCategory, Map<String, Map<Integer, Integer>>> teamSubjectiveRanks = gatherRankedSubjectiveTeams(
            connection, subjectiveCategories, winnerCriteria, tournament, awardGroup);

    final Map<Integer, Integer> teamPerformanceRanks = gatherRankedPerformanceTeams(connection, winnerCriteria,
            tournament, awardGroup);//from ww w  .  j  ava 2 s  . c  o m

    ResultSet rawScoreRS = null;
    PreparedStatement teamPrep = null;
    ResultSet teamsRS = null;
    PreparedStatement scorePrep = null;
    try {
        final StringBuilder query = new StringBuilder();
        query.append(
                "SELECT Teams.Organization,Teams.TeamName,Teams.TeamNumber,FinalScores.OverallScore,FinalScores.performance,current_tournament_teams.judging_station");
        for (int cat = 0; cat < subjectiveCategories.length; cat++) {
            if (weights[cat] > 0.0) {
                final String catName = subjectiveCategories[cat].getName();
                query.append(",FinalScores." + catName);
            }
        }
        query.append(" FROM Teams,FinalScores,current_tournament_teams");
        query.append(" WHERE FinalScores.TeamNumber = Teams.TeamNumber");
        query.append(" AND FinalScores.Tournament = ?");
        query.append(" AND current_tournament_teams.event_division = ?");
        query.append(" AND current_tournament_teams.TeamNumber = Teams.TeamNumber");
        query.append(
                " ORDER BY FinalScores.OverallScore " + winnerCriteria.getSortString() + ", Teams.TeamNumber");
        teamPrep = connection.prepareStatement(query.toString());
        teamPrep.setInt(1, tournament.getTournamentID());
        teamPrep.setString(2, awardGroup);
        teamsRS = teamPrep.executeQuery();

        scorePrep = connection
                .prepareStatement("SELECT score FROM performance_seeding_max" + " WHERE TeamNumber = ?");

        while (teamsRS.next()) {
            final int teamNumber = teamsRS.getInt(3);
            final String organization = teamsRS.getString(1);
            final String teamName = teamsRS.getString(2);
            final String judgingGroup = teamsRS.getString(6);

            final double totalScore;
            final double ts = teamsRS.getDouble(4);
            if (teamsRS.wasNull()) {
                totalScore = Double.NaN;
            } else {
                totalScore = ts;
            }

            // ///////////////////////////////////////////////////////////////////
            // Build a table of data for this team
            // ///////////////////////////////////////////////////////////////////
            final PdfPTable curteam = new PdfPTable(relativeWidths);
            curteam.getDefaultCell().setBorder(0);

            // The first row of the team table...
            // First column is organization name
            final PdfPCell teamCol = new PdfPCell(new Phrase(organization, ARIAL_8PT_NORMAL));
            teamCol.setBorder(0);
            teamCol.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_LEFT);
            curteam.addCell(teamCol);
            curteam.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT);

            final PdfPCell judgeGroupCell = new PdfPCell(new Phrase(judgingGroup, ARIAL_8PT_NORMAL));
            judgeGroupCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
            judgeGroupCell.setBorder(0);
            curteam.addCell(judgeGroupCell);

            // Second column is "Raw:"
            final PdfPCell rawLabel = new PdfPCell(new Phrase("Raw:", ARIAL_8PT_NORMAL));
            rawLabel.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT);
            rawLabel.setBorder(0);
            curteam.addCell(rawLabel);

            insertRawScoreColumns(connection, tournament, winnerCriteria.getSortString(), subjectiveCategories,
                    weights, teamNumber, curteam);

            // Column for the highest performance score of the seeding rounds
            scorePrep.setInt(1, teamNumber);
            rawScoreRS = scorePrep.executeQuery();
            final double rawScore;
            if (rawScoreRS.next()) {
                final double v = rawScoreRS.getDouble(1);
                if (rawScoreRS.wasNull()) {
                    rawScore = Double.NaN;
                } else {
                    rawScore = v;
                }
            } else {
                rawScore = Double.NaN;
            }
            PdfPCell pCell = new PdfPCell((Double.isNaN(rawScore) ? new Phrase("No Score", ARIAL_8PT_NORMAL_RED)
                    : new Phrase(Utilities.NUMBER_FORMAT_INSTANCE.format(rawScore), ARIAL_8PT_NORMAL)));
            pCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
            pCell.setBorder(0);
            curteam.addCell(pCell);
            rawScoreRS.close();

            // The "Overall score" column is not filled in for raw scores
            curteam.addCell("");

            // The second row of the team table...
            // First column contains the team # and name
            final PdfPCell teamNameCol = new PdfPCell(
                    new Phrase(Integer.toString(teamNumber) + " " + teamName, ARIAL_8PT_NORMAL));
            teamNameCol.setBorder(0);
            teamNameCol.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_LEFT);
            curteam.addCell(teamNameCol);

            // Second column contains "Scaled:"
            final PdfPCell scaledCell = new PdfPCell(new Phrase("Scaled:", ARIAL_8PT_NORMAL));
            scaledCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT);
            scaledCell.setBorder(0);
            scaledCell.setColspan(2);
            curteam.addCell(scaledCell);

            // Next, one column containing the scaled score for each subjective
            // category with weight > 0
            for (int cat = 0; cat < subjectiveCategories.length; cat++) {
                final Map<String, Map<Integer, Integer>> catRanks = teamSubjectiveRanks
                        .get(subjectiveCategories[cat]);

                final double catWeight = weights[cat];
                if (catWeight > 0.0) {
                    final double scaledScore;
                    final double v = teamsRS.getDouble(6 + cat + 1);
                    if (teamsRS.wasNull()) {
                        scaledScore = Double.NaN;
                    } else {
                        scaledScore = v;
                    }

                    final Map<Integer, Integer> judgingRanks = catRanks.get(judgingGroup);

                    Font scoreFont;
                    final String rankText;
                    if (judgingRanks.containsKey(teamNumber)) {
                        final int rank = judgingRanks.get(teamNumber);
                        rankText = String.format("%1$s(%2$d)", Utilities.NON_BREAKING_SPACE, rank);
                        if (1 == rank) {
                            scoreFont = ARIAL_8PT_BOLD;
                        } else {
                            scoreFont = ARIAL_8PT_NORMAL;
                        }
                    } else {
                        rankText = String.format("%1$s%1$s%1$s%1$s%1$s", Utilities.NON_BREAKING_SPACE);
                        scoreFont = ARIAL_8PT_NORMAL;
                    }

                    final String scoreText;
                    if (Double.isNaN(scaledScore)) {
                        scoreText = "No Score" + rankText;
                        scoreFont = ARIAL_8PT_NORMAL_RED;
                    } else {
                        scoreText = Utilities.NUMBER_FORMAT_INSTANCE.format(scaledScore) + rankText;
                    }

                    final PdfPCell subjCell = new PdfPCell(new Phrase(scoreText, scoreFont));
                    subjCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
                    subjCell.setBorder(0);
                    curteam.addCell(subjCell);
                }
            } // foreach category

            // 2nd to last column has the scaled performance score
            {
                Font scoreFont;
                final String rankText;
                if (teamPerformanceRanks.containsKey(teamNumber)) {
                    final int rank = teamPerformanceRanks.get(teamNumber);
                    rankText = String.format("%1$s(%2$d)", Utilities.NON_BREAKING_SPACE, rank);
                    if (1 == rank) {
                        scoreFont = ARIAL_8PT_BOLD;
                    } else {
                        scoreFont = ARIAL_8PT_NORMAL;
                    }
                } else {
                    rankText = String.format("%1$s%1$s%1$s%1$s%1$s", Utilities.NON_BREAKING_SPACE);
                    scoreFont = ARIAL_8PT_NORMAL;
                }

                final double scaledScore;
                final double v = teamsRS.getDouble(5);
                if (teamsRS.wasNull()) {
                    scaledScore = Double.NaN;
                } else {
                    scaledScore = v;
                }

                final String scaledScoreStr;
                if (Double.isNaN(scaledScore)) {
                    scoreFont = ARIAL_8PT_NORMAL_RED;
                    scaledScoreStr = "No Score" + rankText;
                } else {
                    scaledScoreStr = Utilities.NUMBER_FORMAT_INSTANCE.format(scaledScore) + rankText;
                }

                pCell = new PdfPCell(new Phrase(scaledScoreStr, scoreFont));
                pCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
                pCell.setBorder(0);
                curteam.addCell(pCell);
            } // performance score

            // Last column contains the overall scaled score
            final String overallScoreSuffix;
            if (bestTeams.contains(teamNumber)) {
                overallScoreSuffix = String.format("%1$s*", Utilities.NON_BREAKING_SPACE);
            } else {
                overallScoreSuffix = String.format("%1$s%1$s", Utilities.NON_BREAKING_SPACE);
            }

            pCell = new PdfPCell((Double.isNaN(totalScore)
                    ? new Phrase("No Score" + overallScoreSuffix, ARIAL_8PT_NORMAL_RED)
                    : new Phrase(Utilities.NUMBER_FORMAT_INSTANCE.format(totalScore) + overallScoreSuffix,
                            ARIAL_8PT_NORMAL)));
            pCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
            pCell.setBorder(0);
            curteam.addCell(pCell);

            // This is an empty row in the team table that is added to put a
            // horizontal rule under the team's score in the display
            final PdfPCell blankCell = new PdfPCell();
            blankCell.setBorder(0);
            blankCell.setBorderWidthBottom(0.5f);
            blankCell.setBorderColorBottom(BaseColor.GRAY);
            blankCell.setColspan(relativeWidths.length);
            curteam.addCell(blankCell);

            // Create a new cell and add it to the division table - this cell will
            // contain the entire team table we just built above
            final PdfPCell curteamCell = new PdfPCell(curteam);
            curteamCell.setBorder(0);
            curteamCell.setColspan(relativeWidths.length);
            divTable.addCell(curteamCell);
        }

        teamsRS.close();

    } finally {
        SQLFunctions.close(teamsRS);
        SQLFunctions.close(teamPrep);
        SQLFunctions.close(rawScoreRS);
        SQLFunctions.close(scorePrep);
    }

}

From source file:jdbreport.model.io.pdf.itext5.PdfWriter.java

License:Apache License

private void assignBorders(CellStyle style, PdfPCell pdfCell) {
    pdfCell.setBorderWidth(0);/*from   w  w  w.j a  v a2  s  . co m*/
    Border border = style.getBorders(Border.LINE_LEFT);
    if (border != null) {
        pdfCell.setBorderWidthLeft(border.getLineWidth());
        pdfCell.setBorderColorLeft(new BaseColor(border.getColor().getRGB()));
    }
    border = style.getBorders(Border.LINE_RIGHT);
    if (border != null) {
        pdfCell.setBorderWidthRight(border.getLineWidth());
        pdfCell.setBorderColorRight(new BaseColor(border.getColor().getRGB()));
    }
    border = style.getBorders(Border.LINE_TOP);
    if (border != null) {
        pdfCell.setBorderWidthTop(border.getLineWidth());
        pdfCell.setBorderColorTop(new BaseColor(border.getColor().getRGB()));
    }
    border = style.getBorders(Border.LINE_BOTTOM);
    if (border != null) {
        pdfCell.setBorderWidthBottom(border.getLineWidth());
        pdfCell.setBorderColorBottom(new BaseColor(border.getColor().getRGB()));
    }
}

From source file:net.digitstar.vanadio.helpers.PdfHelper.java

License:Apache License

public static PdfPCell newCell(CellStyle style) {
    PdfPCell cell = new PdfPCell();
    if (style != null) {
        if (style.getNestedTable() != null) {
            cell = new PdfPCell(style.getNestedTable());
            style.setNestedTable(null);/* ww w . j a v  a 2 s .  c  o m*/
        } else if (style.getImage() != null) {
            cell = new PdfPCell(style.getImage(), style.isFitImage());
            style.setImage(null);
        } else if (style.getText() != null) {
            cell = new PdfPCell(style.getText());
            style.setText((String) null);
        }

        cell.setColspan(style.getColspan());
        cell.setRowspan(style.getRowspan());

        cell.setMinimumHeight(style.getMinimumHeight());
        cell.setFixedHeight(style.getFixedHeight());

        cell.setNoWrap(style.isNoWrap());

        cell.setRotation(style.getRotation().getValue());

        style = Alignment.assign(style);

        cell.setHorizontalAlignment(style.getHorizAlign().getValue());
        cell.setVerticalAlignment(style.getVertAlign().getValue());

        cell.setUseVariableBorders(style.isUseVariableBorders());
        cell.setUseBorderPadding(style.isUseBorderPadding());

        if (!style.getBorderWidth().isAllSideEqual()) {
            cell.setBorderWidthBottom(style.getBorderWidth().getBottom());
            cell.setBorderWidthLeft(style.getBorderWidth().getLeft());
            cell.setBorderWidthRight(style.getBorderWidth().getRight());
            cell.setBorderWidthTop(style.getBorderWidth().getTop());
        } else {
            cell.setBorderWidth(style.getBorderWidth().getValue());
        }

        cell.setPaddingBottom(style.getPadding().getBottom());
        cell.setPaddingLeft(style.getPadding().getLeft());
        cell.setPaddingRight(style.getPadding().getRight());
        cell.setPaddingTop(style.getPadding().getTop());

        cell.setBorderColorBottom(style.getBorderColor().getBottom());
        cell.setBorderColorLeft(style.getBorderColor().getLeft());
        cell.setBorderColorRight(style.getBorderColor().getRight());
        cell.setBorderColorTop(style.getBorderColor().getTop());

        cell.setBorder(style.getBorder().getValue());

        cell.setBackgroundColor(style.getBackgroundColor());
        if (style.getGreyFill() >= 0) {
            cell.setGrayFill(style.getGreyFill());
        }
    }
    return cell;
}

From source file:ro.nextreports.engine.exporter.PdfExporter.java

License:Apache License

private PdfPCell renderPdfCell(BandElement bandElement, Object value, int gridRow, int rowSpan, int colSpan,
        boolean image, int column) {
    Map<String, Object> style = buildCellStyleMap(bandElement, value, gridRow, column, colSpan);

    FontFactoryImp fact = new FontFactoryImp();
    com.itextpdf.text.Font fnt;//from  ww w  . j a  v a2  s. c om
    if (bandElement != null) {
        fontName = (String) style.get(StyleFormatConstants.FONT_NAME_KEY);
        int size = ((Float) style.get(StyleFormatConstants.FONT_SIZE)).intValue();
        fnt = getFont(size);
    } else {
        fnt = getFont(10);
    }

    PdfPCell cell;
    if (image) {
        if (value == null) {
            cell = new PdfPCell(new Phrase(IMAGE_NOT_FOUND));
        } else {
            ImageBandElement ibe = (ImageBandElement) bandElement;
            try {
                byte[] imageBytes = getImage((String) value);
                cell = getImageCell(ibe, imageBytes, column, colSpan);
            } catch (Exception e) {
                cell = new PdfPCell(new Phrase(IMAGE_NOT_LOADED));
            }
        }
    } else if (bandElement instanceof HyperlinkBandElement) {
        Hyperlink hyperlink = ((HyperlinkBandElement) bandElement).getHyperlink();
        Anchor anchor = new Anchor(hyperlink.getText(), fnt);
        anchor.setReference(hyperlink.getUrl());
        Phrase ph = new Phrase();
        ph.add(anchor);
        cell = new PdfPCell(ph);
    } else if (bandElement instanceof ReportBandElement) {
        Report report = ((ReportBandElement) bandElement).getReport();
        ExporterBean eb = null;
        try {
            eb = getSubreportExporterBean(report);
            PdfExporter subExporter = new PdfExporter(eb);
            subExporter.export();
            PdfPTable innerTable = subExporter.getTable();
            cell = new PdfPCell(innerTable);
        } catch (Exception e) {
            cell = new PdfPCell();
            e.printStackTrace();
        } finally {
            if ((eb != null) && (eb.getResult() != null)) {
                eb.getResult().close();
            }
        }
    } else if ((bandElement instanceof VariableBandElement) && (VariableFactory
            .getVariable(((VariableBandElement) bandElement).getVariable()) instanceof TotalPageNoVariable)) {
        try {
            cell = new PdfPCell(Image.getInstance(total));
        } catch (BadElementException e) {
            cell = new PdfPCell(new Phrase("NA"));
        }

    } else if (bandElement instanceof ImageColumnBandElement) {
        try {
            String v = StringUtil.getValueAsString(value, null);
            if (StringUtil.BLOB.equals(v)) {
                cell = new PdfPCell(new Phrase(StringUtil.BLOB));
            } else {
                byte[] bytes = StringUtil.decodeImage(v);
                cell = getImageCell(bandElement, bytes, column, colSpan);
            }
        } catch (Exception e) {
            e.printStackTrace();
            cell = new PdfPCell(new Phrase(IMAGE_NOT_LOADED));
        }
    } else {
        String stringValue;
        if (style.containsKey(StyleFormatConstants.PATTERN)) {
            stringValue = StringUtil.getValueAsString(value, (String) style.get(StyleFormatConstants.PATTERN),
                    getReportLanguage());
        } else {
            stringValue = StringUtil.getValueAsString(value, null, getReportLanguage());
        }
        if (stringValue == null) {
            stringValue = "";
        }
        if (stringValue.startsWith("<html>")) {
            StringReader reader = new StringReader(stringValue);
            List<Element> elems = new ArrayList<Element>();
            try {
                elems = HTMLWorker.parseToList(reader, new StyleSheet());
                Phrase ph = new Phrase();
                for (int i = 0; i < elems.size(); i++) {
                    Element elem = (Element) elems.get(i);
                    ph.add(elem);
                }
                cell = new PdfPCell(ph);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Phrase ph = new Phrase(stringValue, fnt);
                cell = new PdfPCell(ph);
            }

        } else {
            Phrase ph = new Phrase(stringValue, fnt);
            cell = new PdfPCell(ph);
        }
    }

    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell.setUseDescender(true); // needed for a cell without padding
    cell.setMinimumHeight(MINIMUM_HEIGHT); // needed if there is a row in which all cells are empty

    if (bandElement != null) {
        cell.setRotation(bandElement.getTextRotation());
    }

    if (colSpan > 1) {
        cell.setColspan(colSpan);
    }

    if (rowSpan > 1) {
        cell.setRowspan(rowSpan);
    }

    if (style != null) {

        updateFont(style, fnt);

        if (style.containsKey(StyleFormatConstants.BACKGROUND_COLOR)) {
            Color val = (Color) style.get(StyleFormatConstants.BACKGROUND_COLOR);
            cell.setBackgroundColor(new BaseColor(val));
        }
        if (style.containsKey(StyleFormatConstants.HORIZONTAL_ALIGN_KEY)) {
            if (StyleFormatConstants.HORIZONTAL_ALIGN_LEFT
                    .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) {
                cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
            }
            if (StyleFormatConstants.HORIZONTAL_ALIGN_RIGHT
                    .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) {
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            }
            if (StyleFormatConstants.HORIZONTAL_ALIGN_CENTER
                    .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) {
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            }
        }

        if (style.containsKey(StyleFormatConstants.VERTICAL_ALIGN_KEY)) {
            if (StyleFormatConstants.VERTICAL_ALIGN_TOP
                    .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) {
                cell.setVerticalAlignment(Element.ALIGN_TOP);
            }
            if (StyleFormatConstants.VERTICAL_ALIGN_MIDDLE
                    .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) {
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            }
            if (StyleFormatConstants.VERTICAL_ALIGN_BOTTOM
                    .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) {
                cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
            }
        }

        if (style.containsKey(StyleFormatConstants.PADDING_LEFT)) {
            Float val = (Float) style.get(StyleFormatConstants.PADDING_LEFT);
            cell.setPaddingLeft(val);
        }
        if (style.containsKey(StyleFormatConstants.PADDING_RIGHT)) {
            Float val = (Float) style.get(StyleFormatConstants.PADDING_RIGHT);
            cell.setPaddingRight(val);
        }
        if (style.containsKey(StyleFormatConstants.PADDING_TOP)) {
            Float val = (Float) style.get(StyleFormatConstants.PADDING_TOP);
            cell.setPaddingTop(val);
        }
        if (style.containsKey(StyleFormatConstants.PADDING_BOTTOM)) {
            Float val = (Float) style.get(StyleFormatConstants.PADDING_BOTTOM);
            cell.setPaddingBottom(val);
        }
        cell.setBorderWidth(0);

        if (style.containsKey(StyleFormatConstants.BORDER_LEFT)) {
            Float val = (Float) style.get(StyleFormatConstants.BORDER_LEFT);
            cell.setBorderWidthLeft(val / 2);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_LEFT_COLOR);
            cell.setBorderColorLeft(new BaseColor(color));
        }
        if (style.containsKey(StyleFormatConstants.BORDER_RIGHT)) {
            Float val = (Float) style.get(StyleFormatConstants.BORDER_RIGHT);
            cell.setBorderWidthRight(val / 2);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_RIGHT_COLOR);
            cell.setBorderColorRight(new BaseColor(color));
        }
        if (style.containsKey(StyleFormatConstants.BORDER_TOP)) {
            Float val = (Float) style.get(StyleFormatConstants.BORDER_TOP);
            cell.setBorderWidthTop(val / 2);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_TOP_COLOR);
            cell.setBorderColorTop(new BaseColor(color));
        }
        if (style.containsKey(StyleFormatConstants.BORDER_BOTTOM)) {
            Float val = (Float) style.get(StyleFormatConstants.BORDER_BOTTOM);
            cell.setBorderWidthBottom(val / 2);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_BOTTOM_COLOR);
            cell.setBorderColorBottom(new BaseColor(color));
        }

        // for subreports we use default no wrap
        if (cell.getTable() == null) {
            cell.setNoWrap(true);
            if (bandElement != null) {
                if (bandElement.isWrapText()) {
                    cell.setNoWrap(false);
                }
            }
        }

        // to see a background image all cells must not have any background!
        if (bean.getReportLayout().getBackgroundImage() != null) {
            cell.setBackgroundColor(null);
        }
    }
    return cell;
}