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

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

Introduction

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

Prototype

public void setColspan(int colspan) 

Source Link

Document

Setter for property colspan.

Usage

From source file:fll.web.playoff.ScoresheetGenerator.java

License:Open Source License

public void writeFile(final OutputStream out, final boolean orientationIsPortrait) throws DocumentException {

    // This creates our new PDF document and declares its orientation
    Document pdfDoc;//  www.  jav  a2 s.  com
    if (orientationIsPortrait) {
        pdfDoc = new Document(PageSize.LETTER); // portrait
    } else {
        pdfDoc = new Document(PageSize.LETTER.rotate()); // landscape
    }
    PdfWriter.getInstance(pdfDoc, out);

    // Measurements are always in points (72 per inch)
    // This sets up 1/2 inch margins side margins and 0.35in top and bottom
    // margins
    pdfDoc.setMargins(0.5f * POINTS_PER_INCH, 0.5f * POINTS_PER_INCH, 0.35f * POINTS_PER_INCH,
            0.35f * POINTS_PER_INCH);
    pdfDoc.open();

    // Header cell with challenge title to add to both scoresheets
    final Paragraph titleParagraph = new Paragraph();
    final Chunk titleChunk = new Chunk(m_pageTitle,
            FontFactory.getFont(FontFactory.HELVETICA_BOLD, 14, Font.NORMAL, BaseColor.WHITE));
    titleParagraph.setAlignment(Element.ALIGN_CENTER);
    titleParagraph.add(titleChunk);

    titleParagraph.add(Chunk.NEWLINE);
    final Chunk swVersionChunk = new Chunk("SW version: " + Version.getVersion(),
            FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE));
    titleParagraph.add(swVersionChunk);
    if (null != m_revision) {

        final Chunk revisionChunk = new Chunk(" Descriptor revision: " + m_revision,
                FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE));

        titleParagraph.add(revisionChunk);
    }

    final PdfPCell head = new PdfPCell();
    head.setColspan(2);
    head.setBorder(1);
    head.setPaddingTop(0);
    head.setPaddingBottom(3);
    head.setBackgroundColor(new BaseColor(64, 64, 64));
    head.setVerticalAlignment(Element.ALIGN_TOP);
    head.addElement(titleParagraph);

    // Cells for score field, and 2nd check initials
    final Phrase des = new Phrase("Data Entry Score _______", ARIAL_8PT_NORMAL);
    final PdfPCell desC = new PdfPCell(des);
    desC.setBorder(0);
    desC.setPaddingTop(9);
    desC.setPaddingRight(36);
    desC.setHorizontalAlignment(Element.ALIGN_RIGHT);
    final Phrase sci = new Phrase("2nd Check Initials _______", ARIAL_8PT_NORMAL);
    final PdfPCell sciC = new PdfPCell(sci);
    sciC.setBorder(0);
    sciC.setPaddingTop(9);
    sciC.setPaddingRight(36);
    sciC.setHorizontalAlignment(Element.ALIGN_RIGHT);

    // Create a table with a grid cell for each scoresheet on the page
    PdfPTable wholePage = getTableForPage(orientationIsPortrait);
    wholePage.setWidthPercentage(100);
    for (int i = 0; i < m_numSheets; i++) {
        if (i > 0 && (orientationIsPortrait || (i % 2) == 0)) {
            pdfDoc.newPage();
            wholePage = getTableForPage(orientationIsPortrait);
            wholePage.setWidthPercentage(100);
        }

        // This table is a single score sheet
        final PdfPTable scoreSheet = new PdfPTable(2);
        // scoreSheet.getDefaultCell().setBorder(Rectangle.LEFT | Rectangle.BOTTOM
        // | Rectangle.RIGHT | Rectangle.TOP); //FIXME DEBUG should be NO_BORDER
        scoreSheet.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        scoreSheet.getDefaultCell().setPaddingRight(1);
        scoreSheet.getDefaultCell().setPaddingLeft(0);

        scoreSheet.addCell(head);

        final PdfPTable teamInfo = new PdfPTable(7);
        teamInfo.setWidthPercentage(100);
        teamInfo.setWidths(new float[] { 1f, 1f, 1f, 1f, 1f, 1f, .9f });

        // Time label cell
        final Paragraph timeP = new Paragraph("Time:", ARIAL_10PT_NORMAL);
        timeP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell timeLc = new PdfPCell(scoreSheet.getDefaultCell());
        timeLc.addElement(timeP);
        teamInfo.addCell(timeLc);
        // Time value cell
        final Paragraph timeV = new Paragraph(null == m_time[i] ? SHORT_BLANK : m_time[i], COURIER_10PT_NORMAL);
        final PdfPCell timeVc = new PdfPCell(scoreSheet.getDefaultCell());
        timeVc.addElement(timeV);
        teamInfo.addCell(timeVc);

        // Table label cell
        final Paragraph tblP = new Paragraph("Table:", ARIAL_10PT_NORMAL);
        tblP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell tblLc = new PdfPCell(scoreSheet.getDefaultCell());
        tblLc.addElement(tblP);
        teamInfo.addCell(tblLc);
        // Table value cell
        final Paragraph tblV = new Paragraph(m_table[i], COURIER_10PT_NORMAL);
        final PdfPCell tblVc = new PdfPCell(scoreSheet.getDefaultCell());
        tblVc.addElement(tblV);
        teamInfo.addCell(tblVc);

        // Round number label cell
        final Paragraph rndP = new Paragraph("Round:", ARIAL_10PT_NORMAL);
        rndP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell rndlc = new PdfPCell(scoreSheet.getDefaultCell());
        rndlc.addElement(rndP);
        teamInfo.addCell(rndlc);
        // Round number value cell
        final Paragraph rndV = new Paragraph(m_round[i], COURIER_10PT_NORMAL);
        final PdfPCell rndVc = new PdfPCell(scoreSheet.getDefaultCell());
        // rndVc.setColspan(2);
        rndVc.addElement(rndV);
        teamInfo.addCell(rndVc);

        final PdfPCell temp1 = new PdfPCell(scoreSheet.getDefaultCell());
        // temp1.setColspan(2);
        temp1.addElement(new Paragraph("Judge ____", ARIAL_8PT_NORMAL));
        teamInfo.addCell(temp1);

        // Team number label cell
        final Paragraph nbrP = new Paragraph("Team #:", ARIAL_10PT_NORMAL);
        nbrP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell nbrlc = new PdfPCell(scoreSheet.getDefaultCell());
        nbrlc.addElement(nbrP);
        teamInfo.addCell(nbrlc);
        // Team number value cell
        final Paragraph nbrV = new Paragraph(null == m_number[i] ? SHORT_BLANK : String.valueOf(m_number[i]),
                COURIER_10PT_NORMAL);
        final PdfPCell nbrVc = new PdfPCell(scoreSheet.getDefaultCell());
        nbrVc.addElement(nbrV);
        teamInfo.addCell(nbrVc);

        // Team division label cell
        final Paragraph divP = new Paragraph(m_divisionLabel[i], ARIAL_10PT_NORMAL);
        divP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell divlc = new PdfPCell(scoreSheet.getDefaultCell());
        divlc.addElement(divP);
        divlc.setColspan(2);
        teamInfo.addCell(divlc);
        // Team division value cell
        final Paragraph divV = new Paragraph(m_division[i], COURIER_10PT_NORMAL);
        final PdfPCell divVc = new PdfPCell(scoreSheet.getDefaultCell());
        divVc.setColspan(2);
        divVc.addElement(divV);
        teamInfo.addCell(divVc);

        final PdfPCell temp2 = new PdfPCell(scoreSheet.getDefaultCell());
        // temp2.setColspan(2);
        temp2.addElement(new Paragraph("Team ____", ARIAL_8PT_NORMAL));
        teamInfo.addCell(temp2);

        // Team name label cell
        final Paragraph nameP = new Paragraph("Team Name:", ARIAL_10PT_NORMAL);
        nameP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell namelc = new PdfPCell(scoreSheet.getDefaultCell());
        namelc.setColspan(2);
        namelc.addElement(nameP);
        teamInfo.addCell(namelc);
        // Team name value cell
        final Paragraph nameV = new Paragraph(m_name[i], COURIER_10PT_NORMAL);
        final PdfPCell nameVc = new PdfPCell(scoreSheet.getDefaultCell());
        nameVc.setColspan(5);
        nameVc.addElement(nameV);
        teamInfo.addCell(nameVc);

        // add team info cell to the team table
        final PdfPCell teamInfoCell = new PdfPCell(scoreSheet.getDefaultCell());
        teamInfoCell.addElement(teamInfo);
        teamInfoCell.setColspan(2);

        scoreSheet.addCell(teamInfoCell);

        if (null != m_goalsTable) {
            final PdfPCell goalCell = new PdfPCell(m_goalsTable);
            goalCell.setBorder(0);
            goalCell.setPadding(0);
            goalCell.setColspan(2);
            scoreSheet.addCell(goalCell);
        }

        scoreSheet.addCell(desC);
        scoreSheet.addCell(sciC);

        if (null != m_copyright) {
            final Phrase copyright = new Phrase("\u00A9" + m_copyright, f6i);
            final PdfPCell copyrightC = new PdfPCell(scoreSheet.getDefaultCell());
            copyrightC.addElement(copyright);
            copyrightC.setBorder(0);
            copyrightC.setHorizontalAlignment(Element.ALIGN_CENTER);
            copyrightC.setColspan(2);

            scoreSheet.addCell(copyrightC);
        }

        // the cell in the whole page table that will contain the single score
        // sheet
        final PdfPCell scoresheetCell = new PdfPCell(scoreSheet);
        scoresheetCell.setBorder(0);
        scoresheetCell.setPadding(0);

        // Interior borders between scoresheets on a page
        if (!orientationIsPortrait) {
            if (i % 2 == 0) {
                scoresheetCell.setPaddingRight(0.1f * POINTS_PER_INCH);
            } else {
                scoresheetCell.setPaddingLeft(0.1f * POINTS_PER_INCH);
            }
        }

        // Add the current scoresheet to the page
        wholePage.addCell(scoresheetCell);

        // Add the current table of scoresheets to the document
        if (orientationIsPortrait || (i % 2 != 0)) {
            pdfDoc.add(wholePage);
        }
    }

    // Add a blank cells to complete the table of the last page
    if (!orientationIsPortrait && m_numSheets % 2 != 0) {
        final PdfPCell blank = new PdfPCell();
        blank.setBorder(0);
        wholePage.addCell(blank);
        pdfDoc.add(wholePage);
    }

    pdfDoc.close();
}

From source file:fll.web.playoff.ScoresheetGenerator.java

License:Open Source License

/**
 * Stores the goal cells that are inserted into the output after the team name
 * headers and before the scoring/initials blanks at the bottom of the
 * scoresheet.//from   ww w  . j a v  a  2 s  .  c om
 */
private void setChallengeInfo(final ChallengeDescription description) {
    setPageTitle(description.getTitle());

    if (null != description.getRevision()) {
        setRevisionInfo(description.getRevision());
    }

    if (null != description.getCopyright()) {
        m_copyright = description.getCopyright();
    } else {
        m_copyright = null;
    }

    final PerformanceScoreCategory performanceElement = description.getPerformance();
    // use ArrayList as we will be doing indexed access in the loop
    final List<AbstractGoal> goals = new ArrayList<>(performanceElement.getGoals());

    final float[] relativeWidths = new float[3];
    relativeWidths[0] = 4;
    relativeWidths[1] = 48;
    relativeWidths[2] = 48;
    m_goalsTable = new PdfPTable(relativeWidths);

    String prevCategory = null;
    for (int goalIndex = 0; goalIndex < goals.size(); ++goalIndex) {
        final AbstractGoal goal = goals.get(goalIndex);
        if (!goal.isComputed()) {
            final String category = goal.getCategory();

            // add category cell if needed
            boolean firstRowInCategory = false;
            if (!StringUtils.equals(prevCategory, category)) {
                if (!StringUtils.isEmpty(category)) {

                    // find out how many future goals have the same category
                    int categoryRowSpan = 1;
                    for (int otherIndex = goalIndex + 1; otherIndex < goals.size(); ++otherIndex) {
                        final AbstractGoal otherGoal = goals.get(otherIndex);
                        if (!otherGoal.isComputed()) {
                            if (StringUtils.equals(category, otherGoal.getCategory())) {
                                ++categoryRowSpan;
                            } else {
                                break;
                            }
                        }
                    }

                    final Paragraph catPara = new Paragraph(category, ARIAL_10PT_NORMAL);
                    final PdfPCell categoryCell = new PdfPCell(catPara);
                    categoryCell.setBorderWidthTop(1);
                    categoryCell.setBorderWidthBottom(0);
                    categoryCell.setBorderWidthLeft(0);
                    categoryCell.setBorderWidthRight(0);
                    categoryCell.setVerticalAlignment(Element.ALIGN_CENTER);
                    categoryCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    categoryCell.setRotation(90);
                    categoryCell.setRowspan(categoryRowSpan);
                    m_goalsTable.addCell(categoryCell);
                }

                // first row in a new category, which may be empty
                firstRowInCategory = true;
            }

            // This is the text for the left hand "label" cell
            final String title = goal.getTitle();
            final Paragraph p = new Paragraph(title, ARIAL_10PT_NORMAL);
            final PdfPCell goalLabel = new PdfPCell(p);
            goalLabel.setHorizontalAlignment(Element.ALIGN_RIGHT);
            goalLabel.setVerticalAlignment(Element.ALIGN_CENTER);
            if (firstRowInCategory) {
                goalLabel.setBorderWidthTop(1);
                goalLabel.setBorderWidthBottom(0);
                goalLabel.setBorderWidthLeft(0);
                goalLabel.setBorderWidthRight(0);
            } else {
                goalLabel.setBorder(0);
            }
            goalLabel.setPaddingRight(9);
            goalLabel.setVerticalAlignment(Element.ALIGN_TOP);
            if (StringUtils.isEmpty(category)) {
                // category column and goal label column
                goalLabel.setColspan(2);
            }
            m_goalsTable.addCell(goalLabel);

            // define the value cell
            final double min = goal.getMin();
            final String minStr = FP.equals(min, Math.round(min), 1E-6) ? String.valueOf((int) min)
                    : String.valueOf(min);
            final double max = goal.getMax();
            final String maxStr = FP.equals(max, Math.round(max), 1E-6) ? String.valueOf((int) max)
                    : String.valueOf(max);

            // If element has child nodes, then we have an enumerated list
            // of choices. Otherwise it is either yes/no or a numeric field.
            final PdfPCell goalValue = new PdfPCell();
            final Chunk choices = new Chunk("", COURIER_10PT_NORMAL);
            if (goal.isEnumerated()) {
                // replace spaces with "no-break" spaces
                boolean first = true;
                final List<EnumeratedValue> values = goal.getSortedValues();
                for (final EnumeratedValue value : values) {
                    if (!first) {
                        choices.append(" /" + Utilities.NON_BREAKING_SPACE);
                    } else {
                        first = false;
                    }
                    choices.append(value.getTitle().toUpperCase().replace(' ', Utilities.NON_BREAKING_SPACE));
                }
                goalValue.addElement(choices);

            } else {
                if (goal.isYesNo()) {
                    // order of yes/no needs to match ScoreEntry.generateYesNoButtons
                    final Paragraph q = new Paragraph("NO / YES", COURIER_10PT_NORMAL);
                    goalValue.addElement(q);

                } else {
                    final String range = "(" + minStr + " - " + maxStr + ")";
                    final PdfPTable t = new PdfPTable(2);
                    t.setHorizontalAlignment(Element.ALIGN_LEFT);
                    t.setTotalWidth(1 * POINTS_PER_INCH);
                    t.setLockedWidth(true);
                    final Phrase r = new Phrase("", ARIAL_8PT_NORMAL);
                    t.addCell(new PdfPCell(r));
                    final Phrase q = new Phrase(range, ARIAL_8PT_NORMAL);
                    t.addCell(new PdfPCell(q));
                    goalValue.setPaddingTop(9);
                    goalValue.addElement(t);
                }
            }

            if (firstRowInCategory) {
                goalValue.setBorderWidthTop(1);
                goalValue.setBorderWidthBottom(0);
                goalValue.setBorderWidthLeft(0);
                goalValue.setBorderWidthRight(0);
            } else {
                goalValue.setBorder(0);
            }
            goalValue.setVerticalAlignment(Element.ALIGN_MIDDLE);

            m_goalsTable.addCell(goalValue);

            // setup for next loop
            prevCategory = category;
        } // if not computed goal

    } // foreach goal

}

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

License:Open Source License

private void createHeader(final PdfPTable table, final String challengeTitle, final String catTitle,
        final String division, final String judgingGroup, final Tournament tournament)
        throws BadElementException {
    final PdfPCell tournamentCell = PdfUtils
            .createHeaderCell(String.format("%s - %s", challengeTitle, tournament.getName()));
    tournamentCell.setColspan(4);
    table.addCell(tournamentCell);// www.  j  a  v a  2s . c  o m

    final PdfPCell categoryHeader = PdfUtils.createHeaderCell(String
            .format("Category: %s - Award Group: %s - JudgingGroup: %s", catTitle, division, judgingGroup));
    categoryHeader.setColspan(4);
    table.addCell(categoryHeader);

    table.addCell(PdfUtils.createHeaderCell(TournamentSchedule.TEAM_NUMBER_HEADER));
    table.addCell(PdfUtils.createHeaderCell(TournamentSchedule.TEAM_NAME_HEADER));
    table.addCell(PdfUtils.createHeaderCell(TournamentSchedule.ORGANIZATION_HEADER));
    table.addCell(PdfUtils.createHeaderCell("Scaled Score"));

    table.setHeaderRows(3);
}

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

License:Open Source License

/**
 * Generate the actual report.// w w w .  ja  v  a  2s. co m
 */
private void generateReport(final Connection connection, final OutputStream out,
        final ChallengeDescription challengeDescription, final String challengeTitle,
        final Tournament tournament, final PdfPageEventHelper pageHandler, final Set<Integer> bestTeams)
        throws SQLException, IOException {
    if (tournament.getTournamentID() != Queries.getCurrentTournament(connection)) {
        throw new FLLRuntimeException(
                "Cannot generate final score report for a tournament other than the current tournament");
    }

    final WinnerType winnerCriteria = challengeDescription.getWinner();

    final TournamentSchedule schedule;
    if (TournamentSchedule.scheduleExistsInDatabase(connection, tournament.getTournamentID())) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Found a schedule for tournament: " + tournament);
        }
        schedule = new TournamentSchedule(connection, tournament.getTournamentID());
    } else {
        schedule = null;
    }

    try {
        // This creates our new PDF document and declares it to be in portrait
        // orientation
        final Document pdfDoc = PdfUtils.createPortraitPdfDoc(out, pageHandler);

        final Iterator<String> agIter = Queries.getAwardGroups(connection).iterator();
        while (agIter.hasNext()) {
            final String awardGroup = agIter.next();

            final ScoreCategory[] subjectiveCategories = challengeDescription.getSubjectiveCategories()
                    .toArray(new ScoreCategory[0]);

            // Figure out how many subjective categories have weights > 0.
            final double[] weights = new double[subjectiveCategories.length];
            int nonZeroWeights = 0;
            for (int catIndex = 0; catIndex < subjectiveCategories.length; catIndex++) {
                weights[catIndex] = subjectiveCategories[catIndex].getWeight();
                if (weights[catIndex] > 0.0) {
                    nonZeroWeights++;
                }
            }
            // Array of relative widths for the columns of the score page
            // Array length varies with the number of subjective scores weighted >
            // 0.
            final int numColumnsLeftOfSubjective = 3;
            final int numColumnsRightOfSubjective = 2;
            final float[] relativeWidths = new float[numColumnsLeftOfSubjective + nonZeroWeights
                    + numColumnsRightOfSubjective];
            relativeWidths[0] = 3f;
            relativeWidths[1] = 1.0f;
            relativeWidths[2] = 1.0f;
            relativeWidths[relativeWidths.length - numColumnsRightOfSubjective] = 1.5f;
            relativeWidths[relativeWidths.length - numColumnsRightOfSubjective + 1] = 1.5f;
            for (int i = numColumnsLeftOfSubjective; i < numColumnsLeftOfSubjective + nonZeroWeights; i++) {
                relativeWidths[i] = 1.5f;
            }

            // Create a table to hold all the scores for this division
            final PdfPTable divTable = new PdfPTable(relativeWidths);
            divTable.getDefaultCell().setBorder(0);
            divTable.setWidthPercentage(100);

            final PdfPTable header = createHeader(challengeTitle, tournament.getName(), awardGroup);
            final PdfPCell headerCell = new PdfPCell(header);
            headerCell.setColspan(relativeWidths.length);
            divTable.addCell(headerCell);

            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("num relative widths: " + relativeWidths.length);
                for (int i = 0; i < relativeWidths.length; ++i) {
                    LOGGER.trace("\twidth[" + i + "] = " + relativeWidths[i]);
                }
            }

            writeColumnHeaders(schedule, weights, subjectiveCategories, relativeWidths, challengeDescription,
                    divTable);

            writeScores(connection, subjectiveCategories, weights, relativeWidths, awardGroup, winnerCriteria,
                    tournament, divTable, bestTeams);

            // Add the division table to the document
            pdfDoc.add(divTable);

            // If there is another division to process, start it on a new page
            if (agIter.hasNext()) {
                pdfDoc.newPage();
            }
        }

        pdfDoc.close();
    } catch (final ParseException pe) {
        throw new RuntimeException("Error parsing category weight!", pe);
    } catch (final DocumentException de) {
        throw new RuntimeException("Error creating PDF document!", de);
    }
}

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.  ja va  2s  .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:fll.web.report.FinalComputedScores.java

License:Open Source License

/**
 * @throws ParseException/*from w  ww .  j  ava2  s.c o  m*/
 */
private void writeColumnHeaders(final TournamentSchedule schedule, final double[] weights,
        final ScoreCategory[] subjectiveCategories, final float[] relativeWidths,
        final ChallengeDescription challengeDescription, final PdfPTable divTable) throws ParseException {

    // /////////////////////////////////////////////////////////////////////
    // Write the table column headers
    // /////////////////////////////////////////////////////////////////////
    // team information
    final PdfPCell organizationCell = new PdfPCell(new Phrase("Organization", ARIAL_8PT_BOLD));
    organizationCell.setBorder(0);
    organizationCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
    divTable.addCell(organizationCell);

    // judging group
    if (null != schedule) {
        final Paragraph judgingGroup = new Paragraph("Judging", ARIAL_8PT_BOLD);
        judgingGroup.add(Chunk.NEWLINE);
        judgingGroup.add(new Chunk("Group"));
        final PdfPCell osCell = new PdfPCell(judgingGroup);
        osCell.setBorder(0);
        osCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        osCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
        divTable.addCell(osCell);
    }

    divTable.addCell(""); // weight/raw&scaled

    for (int cat = 0; cat < subjectiveCategories.length; cat++) {
        if (weights[cat] > 0.0) {
            final String catTitle = subjectiveCategories[cat].getTitle();

            final Paragraph catPar = new Paragraph(catTitle, ARIAL_8PT_BOLD);
            final PdfPCell catCell = new PdfPCell(catPar);
            catCell.setBorder(0);
            catCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
            catCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
            divTable.addCell(catCell);
        }
    }

    final Paragraph perfPar = new Paragraph("Performance", ARIAL_8PT_BOLD);
    final PdfPCell perfCell = new PdfPCell(perfPar);
    perfCell.setBorder(0);
    perfCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
    perfCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
    divTable.addCell(perfCell);

    final Paragraph overallScore = new Paragraph("Overall", ARIAL_8PT_BOLD);
    overallScore.add(Chunk.NEWLINE);
    overallScore.add(new Chunk("Score"));
    final PdfPCell osCell = new PdfPCell(overallScore);
    osCell.setBorder(0);
    osCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
    osCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
    divTable.addCell(osCell);

    // /////////////////////////////////////////////////////////////////////
    // Write a table row with the relative weights of the subjective scores
    // /////////////////////////////////////////////////////////////////////

    final PdfPCell teamCell = new PdfPCell(new Phrase("Team # / Team Name", ARIAL_8PT_BOLD));
    teamCell.setBorder(0);
    teamCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
    divTable.addCell(teamCell);

    final Paragraph wPar = new Paragraph("Weight:", ARIAL_8PT_NORMAL);
    final PdfPCell wCell = new PdfPCell(wPar);
    if (null != schedule) {
        wCell.setColspan(2);
    }
    wCell.setBorder(0);
    wCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT);
    divTable.addCell(wCell);

    final PdfPCell[] wCells = new PdfPCell[subjectiveCategories.length];
    final Paragraph[] wPars = new Paragraph[subjectiveCategories.length];
    for (int cat = 0; cat < subjectiveCategories.length; cat++) {
        if (weights[cat] > 0.0) {
            wPars[cat] = new Paragraph(Double.toString(weights[cat]), ARIAL_8PT_NORMAL);
            wCells[cat] = new PdfPCell(wPars[cat]);
            wCells[cat].setBorder(0);
            wCells[cat].setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
            divTable.addCell(wCells[cat]);
        }
    }

    final PerformanceScoreCategory performanceElement = challengeDescription.getPerformance();
    final double perfWeight = performanceElement.getWeight();
    final Paragraph perfWeightPar = new Paragraph(Double.toString(perfWeight), ARIAL_8PT_NORMAL);
    final PdfPCell perfWeightCell = new PdfPCell(perfWeightPar);
    perfWeightCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
    perfWeightCell.setBorder(0);
    divTable.addCell(perfWeightCell);

    divTable.addCell("");

    PdfPCell blankCell = new PdfPCell();
    blankCell.setBorder(0);
    blankCell.setBorderWidthBottom(1.0f);
    blankCell.setColspan(relativeWidths.length);
    divTable.addCell(blankCell);

    // Cause the first 4 rows to be repeated on
    // each page - 1 row for box header, 2 rows text headers and 1 for
    // the horizontal line.
    divTable.setHeaderRows(4);
}

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

License:Open Source License

@Override
// initialization of the header table
public void onEndPage(final PdfWriter writer, final Document document) {
    final PdfPTable header = new PdfPTable(2);
    final Phrase p = new Phrase();
    final Chunk ck = new Chunk(_challengeTitle + "\n" + _reportTitle, _font);
    p.add(ck);/*from w  ww.j a v  a2 s  .  c  o m*/
    header.getDefaultCell().setBorderWidth(0);
    header.addCell(p);
    header.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT);
    header.addCell(new Phrase(new Chunk("Tournament: " + _tournament + "\nDate: " + _formattedDate, _font)));
    final PdfPCell blankCell = new PdfPCell();
    blankCell.setBorder(0);
    blankCell.setBorderWidthTop(1.0f);
    blankCell.setColspan(2);
    header.addCell(blankCell);

    final PdfContentByte cb = writer.getDirectContent();
    cb.saveState();
    header.setTotalWidth(document.right() - document.left());
    header.writeSelectedRows(0, -1, document.left(), document.getPageSize().getHeight() - 10, cb);
    cb.restoreState();
}

From source file:FormatoPDF.ClasesPDF.PDF1.java

public void CrearPDF1(String[][] tabla, String txt1, String txt2, String txt3, String txt4, String txt5,
            String txt6, JTable tabla2) {
        String[][] tabla1 = tabla;
        float[] medidas1 = { 8.5f, 9.0f, 7.5f, 3.5f, 4.5f, 4.0f };
        float[] medidas2 = { 7.5f, 3.5f, 7.0f, 5.5f, 4.5f, 4.5f, 4.5f };
        float[] medidas3 = { 6.5f, 20.5f };
        JFileChooser dlg = new JFileChooser();
        int option = dlg.showSaveDialog(dlg);
        if (option == JFileChooser.APPROVE_OPTION) {
            File f = dlg.getSelectedFile();
            String f1 = f.toString();
            try {
                BaseColor MiColor = WebColors.getRGBColor("#04B4AE");
                TablasPDF tab = new TablasPDF();
                ImagenHome img = new ImagenHome();
                Document document = new Document();
                PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(f1 + ".pdf"));
                Paragraph saltolinea = new Paragraph();
                saltolinea.add("\n");
                document.open();//from   w ww  .j av a 2  s  .  c  o  m
                document.add(img.CrearImg());
                DatosEncabezado en = new DatosEncabezado();
                String[][] valores = new String[4][2];
                valores[0][0] = "Dependencia: ";
                valores[0][1] = txt1;
                valores[1][0] = "Expediente: ";
                valores[1][1] = txt2;
                valores[2][0] = "Sesin: ";
                valores[2][1] = txt3;
                valores[3][0] = "Fecha: ";
                valores[3][1] = txt4;
                en.Datos(valores, writer);

                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                boolean color = true;
                PdfPTable tabpdf1 = new PdfPTable(6);
                PdfPCell cell1 = new PdfPCell(
                        new Paragraph("Sesin:", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                PdfPCell cell11 = new PdfPCell(
                        new Paragraph(tabla1[0][1], FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell1.setBackgroundColor(MiColor);
                tabpdf1.addCell(cell1);
                tabpdf1.addCell(cell11);
                PdfPCell cell2 = new PdfPCell(
                        new Paragraph("Fecha:", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                PdfPCell cell22 = new PdfPCell(
                        new Paragraph(tabla1[0][3], FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell2.setBackgroundColor(MiColor);
                tabpdf1.addCell(cell2);
                tabpdf1.addCell(cell22);
                PdfPCell cell3 = new PdfPCell(
                        new Paragraph("Acuerdo:", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                PdfPCell cell33 = new PdfPCell(
                        new Paragraph(txt5, FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell3.setBackgroundColor(MiColor);
                tabpdf1.addCell(cell3);
                tabpdf1.addCell(cell33);
                document.add(tab.DibujarTablaArre1(6, 6, tabla1, medidas1, color, tabpdf1, 1, ""));

                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);

                PdfPTable tabpdf2 = new PdfPTable(7);
                PdfPCell cell1tab2 = new PdfPCell(new Phrase("ESTUDIO DE MERCADO",
                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell1tab2.setBackgroundColor(MiColor);
                cell1tab2.setMinimumHeight(30);
                cell1tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell1tab2.setColspan(7);
                cell1tab2.setRowspan(1);
                cell1tab2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf2.addCell(cell1tab2);

                PdfPCell cell2tab2 = new PdfPCell(new Phrase("Datos de la empresa ",
                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell2tab2.setBackgroundColor(MiColor);
                cell2tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2tab2.setColspan(4);
                cell2tab2.setRowspan(1);
                cell2tab2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf2.addCell(cell2tab2);

                PdfPCell cell3tab2 = new PdfPCell(new Phrase("Datos de cotizacin ",
                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell3tab2.setBackgroundColor(MiColor);
                cell3tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell3tab2.setColspan(3);
                cell3tab2.setRowspan(1);
                cell3tab2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf2.addCell(cell3tab2);

                PdfPCell cell4tab2 = new PdfPCell(new Paragraph("Nombre, Denominacin o Razn Social",
                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell4tab2.setBackgroundColor(MiColor);
                cell4tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell4tab2);
                PdfPCell cell5tab2 = new PdfPCell(
                        new Paragraph("RFC", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell5tab2.setBackgroundColor(MiColor);
                cell5tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell5tab2);
                PdfPCell cell6tab2 = new PdfPCell(new Paragraph("Representante Legal",
                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell6tab2.setBackgroundColor(MiColor);
                cell6tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell6tab2);
                PdfPCell cell7tab2 = new PdfPCell(new Paragraph("Domicilio Fiscal",
                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell7tab2.setBackgroundColor(MiColor);
                cell7tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell7tab2);
                PdfPCell cell8tab2 = new PdfPCell(
                        new Paragraph("Subtotal", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell8tab2.setBackgroundColor(MiColor);
                cell8tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell8tab2);
                PdfPCell cell9tab2 = new PdfPCell(
                        new Paragraph("IVA", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell9tab2.setBackgroundColor(MiColor);
                cell9tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell9tab2);
                PdfPCell cell10tab2 = new PdfPCell(
                        new Paragraph("TOTAL", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell10tab2.setBackgroundColor(MiColor);
                cell10tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell10tab2);

                document.add(tab.DibujarTabla(7, 5, tabla2, medidas2, tabpdf2));
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);

                PdfPTable tabpdf3 = new PdfPTable(2);
                PdfPCell cell1tab3 = new PdfPCell(
                        new Phrase("Observaciones:", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell1tab3.setBackgroundColor(MiColor);
                cell1tab3.setMinimumHeight(60);
                cell1tab3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell1tab3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf3.addCell(cell1tab3);

                PdfPCell cell2tab3 = new PdfPCell(
                        new Phrase(txt6, FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell2tab3.setMinimumHeight(60);
                cell2tab3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2tab3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf3.addCell(cell2tab3);
                tabpdf3.setWidths(medidas3);
                document.add(tabpdf3);

                document.close();
                JOptionPane.showMessageDialog(null, "El archivo se ha guardado", "Exito",
                        JOptionPane.INFORMATION_MESSAGE);

                File path = new File(f1 + ".pdf");
                Desktop.getDesktop().open(path);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error " + e, "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }

From source file:FormatoPDF.ClasesPDF.PDF2.java

public void CrearPDF2(String[][] tabla, String txt1, String txt2, String txt3, String txt4, String txt5,
            String txt6, String txt7, JTable tabla2, String txt8, String txt9, JTable tabla3, String txt10) {
        String[][] tabla1 = tabla;
        float[] medidas1 = { 8.5f, 9.0f, 7.5f, 3.5f, 4.5f, 4.0f };
        float[] medidas2 = { 6.5f, 4.5f, 6.0f, 5.5f, 5.5f, 5.5f, 3.0f, 3.0f };
        float[] medidas3 = { 6.5f, 3.5f, 3.5f, 3.5f, 2.5f, 3.5f, 6.0f, 4.0f, 4.0f };
        float[] medidas4 = { 6.5f, 20.5f };
        JFileChooser dlg = new JFileChooser();
        int option = dlg.showSaveDialog(dlg);
        if (option == JFileChooser.APPROVE_OPTION) {
            File f = dlg.getSelectedFile();
            String f1 = f.toString();
            try {
                BaseColor MiColor = WebColors.getRGBColor("#04B4AE");
                TablasPDF tab = new TablasPDF();
                ImagenHome img = new ImagenHome();
                Document document = new Document();
                PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(f1 + ".pdf"));
                Paragraph saltolinea = new Paragraph();
                saltolinea.add("\n");
                document.open();//  w  w  w .  j a v  a  2s  . c  om
                document.add(img.CrearImg());
                DatosEncabezado en = new DatosEncabezado();
                String[][] valores = new String[4][2];
                valores[0][0] = "Dependencia: ";
                valores[0][1] = txt1;
                valores[1][0] = "Expediente: ";
                valores[1][1] = txt2;
                valores[2][0] = "Sesin: ";
                valores[2][1] = txt3;
                valores[3][0] = "Fecha: ";
                valores[3][1] = txt4;
                en.Datos(valores, writer);

                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                boolean color = true;
                PdfPTable tabpdf1 = new PdfPTable(6);
                PdfPCell cell1 = new PdfPCell(
                        new Paragraph("Sesin:", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                PdfPCell cell11 = new PdfPCell(
                        new Paragraph(tabla1[0][1], FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell1.setBackgroundColor(MiColor);
                tabpdf1.addCell(cell1);
                tabpdf1.addCell(cell11);
                PdfPCell cell2 = new PdfPCell(
                        new Paragraph("Fecha:", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                PdfPCell cell22 = new PdfPCell(
                        new Paragraph(tabla1[0][3], FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell2.setBackgroundColor(MiColor);
                tabpdf1.addCell(cell2);
                tabpdf1.addCell(cell22);
                PdfPCell cell3 = new PdfPCell(
                        new Paragraph("Acuerdo:", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                PdfPCell cell33 = new PdfPCell(
                        new Paragraph(txt5, FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell3.setBackgroundColor(MiColor);
                tabpdf1.addCell(cell3);
                tabpdf1.addCell(cell33);
                document.add(tab.DibujarTablaArre1(6, 6, tabla1, medidas1, color, tabpdf1, 2, txt6));

                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);

                PdfPTable tabpdf2 = new PdfPTable(8);
                tabpdf2.setWidths(medidas2);
                PdfPCell cell1tab2 = new PdfPCell(new Phrase("Datos de la empresa ",
                        FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell1tab2.setBackgroundColor(MiColor);
                cell1tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell1tab2.setColspan(4);
                cell1tab2.setRowspan(2);
                cell1tab2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf2.addCell(cell1tab2);

                PdfPCell cell2tab2 = new PdfPCell(
                        new Phrase("", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell2tab2.setBackgroundColor(MiColor);
                cell2tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2tab2.setColspan(2);
                cell2tab2.setRowspan(1);
                cell2tab2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf2.addCell(cell2tab2);

                PdfPCell cell3tab2 = new PdfPCell(new Phrase("Junta de Aclaraciones",
                        FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell3tab2.setBackgroundColor(MiColor);
                cell3tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell3tab2.setColspan(2);
                cell3tab2.setRowspan(1);
                cell3tab2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf2.addCell(cell3tab2);

                PdfPCell cell4tab2 = new PdfPCell(
                        new Phrase("Fecha:", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell4tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell4tab2.setBackgroundColor(MiColor);
                cell4tab2.setColspan(1);
                cell4tab2.setRowspan(1);
                cell4tab2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf2.addCell(cell4tab2);

                PdfPCell cell5tab2 = new PdfPCell(
                        new Phrase(txt7, FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell5tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell5tab2.setColspan(1);
                cell5tab2.setRowspan(1);
                cell5tab2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf2.addCell(cell5tab2);///////////

                PdfPTable tabpdf3 = new PdfPTable(8);
                document.add(tabpdf2);

                PdfPCell cell1tab3 = new PdfPCell(new Phrase("Nombre, Denominacin o Razn Social",
                        FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell1tab3.setBackgroundColor(MiColor);
                cell1tab3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell1tab3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf3.addCell(cell1tab3);

                PdfPCell cell2tab3 = new PdfPCell(
                        new Phrase("RFC", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell2tab3.setBackgroundColor(MiColor);
                cell2tab3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2tab3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf3.addCell(cell2tab3);

                PdfPCell cell3tab3 = new PdfPCell(new Phrase("Representante Legal",
                        FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell3tab3.setBackgroundColor(MiColor);
                cell3tab3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell3tab3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf3.addCell(cell3tab3);

                PdfPCell cell4tab3 = new PdfPCell(new Phrase("Domicilio Fiscal",
                        FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell4tab3.setBackgroundColor(MiColor);
                cell4tab3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell4tab3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf3.addCell(cell4tab3);

                PdfPCell cell5tab3 = new PdfPCell(new Phrase("Proveedores sancionados",
                        FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell5tab3.setBackgroundColor(MiColor);
                cell5tab3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell5tab3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf3.addCell(cell5tab3);

                PdfPCell cell6tab3 = new PdfPCell(
                        new Phrase("Pgina web", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell6tab3.setBackgroundColor(MiColor);
                cell6tab3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell6tab3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf3.addCell(cell6tab3);

                PdfPCell cell7tab3 = new PdfPCell(
                        new Phrase("Asisti", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell7tab3.setBackgroundColor(MiColor);
                cell7tab3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell7tab3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf3.addCell(cell7tab3);

                PdfPCell cell8tab3 = new PdfPCell(
                        new Phrase("No asisti", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell8tab3.setBackgroundColor(MiColor);
                cell8tab3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell8tab3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf3.addCell(cell8tab3);

                document.add(tab.DibujarTabla(8, 4, tabla2, medidas2, tabpdf3));
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                ///////////////////////
                PdfPTable tabpdf4 = new PdfPTable(9);
                PdfPCell cell1tab4 = new PdfPCell(new Phrase("Nombre, Denominacin o Razn Social",
                        FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell1tab4.setBackgroundColor(MiColor);
                cell1tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell1tab4.setColspan(1);
                cell1tab4.setRowspan(4);
                cell1tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell1tab4);

                PdfPCell cell2tab4 = new PdfPCell(new Phrase("Apertura de Propuestas",
                        FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell2tab4.setBackgroundColor(MiColor);
                cell2tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2tab4.setColspan(5);
                cell2tab4.setRowspan(1);
                cell2tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell2tab4);

                PdfPCell cell3tab4 = new PdfPCell(new Phrase("Notificacin y Lectura de Fallo",
                        FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell3tab4.setBackgroundColor(MiColor);
                cell3tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell3tab4.setColspan(3);
                cell3tab4.setRowspan(1);
                cell3tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell3tab4);

                PdfPCell cell4tab4 = new PdfPCell(
                        new Phrase("Fecha:", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell4tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell4tab4.setBackgroundColor(MiColor);
                cell4tab4.setColspan(2);
                cell4tab4.setRowspan(1);
                cell4tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell4tab4);

                PdfPCell cell5tab4 = new PdfPCell(
                        new Phrase(txt8, FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell5tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell5tab4.setColspan(3);
                cell5tab4.setRowspan(1);
                cell5tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell5tab4);

                PdfPCell cell6tab4 = new PdfPCell(
                        new Phrase("Fecha:", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell6tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell6tab4.setBackgroundColor(MiColor);
                cell6tab4.setColspan(1);
                cell6tab4.setRowspan(1);
                cell6tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell6tab4);

                PdfPCell cell7tab4 = new PdfPCell(
                        new Phrase(txt9, FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell7tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell7tab4.setColspan(2);
                cell7tab4.setRowspan(1);
                cell7tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell7tab4);

                PdfPCell cell8tab4 = new PdfPCell(
                        new Phrase("Tcnica", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell8tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell8tab4.setBackgroundColor(MiColor);
                cell8tab4.setColspan(2);
                cell8tab4.setRowspan(1);
                cell8tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell8tab4);

                PdfPCell cell9tab4 = new PdfPCell(
                        new Phrase("Econmica ", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell9tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell9tab4.setBackgroundColor(MiColor);
                cell9tab4.setColspan(3);
                cell9tab4.setRowspan(1);
                cell9tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell9tab4);

                PdfPCell cell10tab4 = new PdfPCell(new Phrase("Motivo de desechamiento",
                        FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell10tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell10tab4.setBackgroundColor(MiColor);
                cell10tab4.setColspan(1);
                cell10tab4.setRowspan(2);
                cell10tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell10tab4);

                PdfPCell cell11tab4 = new PdfPCell(new Phrase("Empresa Adjudicada",
                        FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell11tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell11tab4.setBackgroundColor(MiColor);
                cell11tab4.setColspan(1);
                cell11tab4.setRowspan(2);
                cell11tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell11tab4);

                PdfPCell cell12tab4 = new PdfPCell(new Phrase("Monto Adjudicado",
                        FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell12tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell12tab4.setBackgroundColor(MiColor);
                cell12tab4.setColspan(1);
                cell12tab4.setRowspan(2);
                cell12tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell12tab4);

                PdfPCell cell13tab4 = new PdfPCell(
                        new Phrase("Presenta", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell13tab4.setBackgroundColor(MiColor);
                cell13tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell13tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell13tab4);

                PdfPCell cell14tab4 = new PdfPCell(
                        new Phrase("No presenta", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell14tab4.setBackgroundColor(MiColor);
                cell14tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell14tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell14tab4);

                PdfPCell cell15tab4 = new PdfPCell(
                        new Phrase("Subtotal ", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell15tab4.setBackgroundColor(MiColor);
                cell15tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell15tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell15tab4);

                PdfPCell cell16tab4 = new PdfPCell(
                        new Phrase("IVA", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell16tab4.setBackgroundColor(MiColor);
                cell16tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell16tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell16tab4);

                PdfPCell cell17tab4 = new PdfPCell(
                        new Phrase("Total", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
                cell17tab4.setBackgroundColor(MiColor);
                cell17tab4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell17tab4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf4.addCell(cell17tab4);

                document.add(tab.DibujarTabla(9, 4, tabla3, medidas3, tabpdf4));
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);

                PdfPTable tabpdf5 = new PdfPTable(2);
                PdfPCell cell1tab5 = new PdfPCell(
                        new Phrase("Observaciones:", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell1tab5.setBackgroundColor(MiColor);
                cell1tab5.setMinimumHeight(60);
                cell1tab5.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell1tab5.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf5.addCell(cell1tab5);

                PdfPCell cell2tab5 = new PdfPCell(
                        new Phrase(txt10, FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell2tab5.setMinimumHeight(60);
                cell2tab5.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2tab5.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf5.addCell(cell2tab5);
                tabpdf5.setWidths(medidas4);
                document.add(tabpdf5);

                document.close();
                JOptionPane.showMessageDialog(null, "El archivo se ha guardado", "Exito",
                        JOptionPane.INFORMATION_MESSAGE);

                File path = new File(f1 + ".pdf");
                Desktop.getDesktop().open(path);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error " + e, "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }

From source file:FormatoPDF.ClasesPDF.TablasPDF.java

public PdfPTable DibujarTablaArre1(int col, int fil, String[][] tabla, float medidas[], boolean x,
            PdfPTable tab, int pdf, String ult) {

        try {/*www.java 2s.com*/
            BaseColor MiColor = WebColors.getRGBColor("#04B4AE");
            tab.setWidths(medidas);
            if (pdf == 2) {
                fil = 7;
            }
            for (int i = 1; i < fil; i++) {
                for (int j = 0; j < col - 2; j++) {
                    if (i == 6) {
                        PdfPCell cell = new PdfPCell(new Phrase("Publicacin de bases: ",
                                FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                        cell.setBackgroundColor(MiColor);
                        tab.addCell(cell);
                        PdfPCell cell2 = new PdfPCell(
                                new Phrase(ult, FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                        cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                        cell2.setColspan(5);
                        cell2.setRowspan(1);
                        tab.addCell(cell2);
                        break;
                    } else {
                        Object obj1 = tabla[i][j];
                        String value1 = obj1.toString();
                        if (x) {
                            if (j == 0 || j == 2) {
                                PdfPCell cell = new PdfPCell(new Paragraph(value1,
                                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                                cell.setBackgroundColor(MiColor);
                                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                                tab.addCell(cell);
                            } else if (j == 3) {
                                PdfPCell cell = new PdfPCell(new Phrase(value1,
                                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                                cell.setColspan(3);
                                cell.setRowspan(1);
                                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                                tab.addCell(cell);
                            } else {
                                PdfPCell cell = new PdfPCell(new Phrase(value1,
                                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                                tab.addCell(cell);
                            }
                        } else {
                            if (j == 3) {
                                PdfPCell cell = new PdfPCell(new Phrase(value1,
                                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                                cell.setColspan(3);
                                cell.setRowspan(1);
                                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                                tab.addCell(cell);
                            } else {
                                PdfPCell cell = new PdfPCell(new Phrase(value1,
                                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                                tab.addCell(cell);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            System.out.println("Error " + e);
        }
        return tab;
    }