Example usage for com.itextpdf.text.pdf PdfPTable setLockedWidth

List of usage examples for com.itextpdf.text.pdf PdfPTable setLockedWidth

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable setLockedWidth.

Prototype

public void setLockedWidth(final boolean lockedWidth) 

Source Link

Document

Uses the value in setTotalWidth() in Document.add().

Usage

From source file:fr.pigouchet.gestion.util.GeneratePdf.java

public static PdfPTable getHeaderTable(int x, int y) {
    PdfPTable table = new PdfPTable(2);
    table.setTotalWidth(527);//from  w  w  w .ja va2 s.c o m
    table.setLockedWidth(true);
    table.getDefaultCell().setFixedHeight(20);
    table.getDefaultCell().setBorder(Rectangle.BOTTOM);
    table.addCell("FOOBAR FILMFESTIVAL");
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
    table.addCell(String.format("Page %d of %d", x, y));
    return table;
}

From source file:fxml.test.PDFService.java

private PdfPTable createDocumentHeader() throws IOException, BadElementException {

    //start creating header for the document......
    PdfPTable headerTable = new PdfPTable(3);
    headerTable.setHorizontalAlignment(Element.ALIGN_LEFT);
    try {//  w  w w.ja v  a2s .  co  m
        headerTable.setTotalWidth(new float[] { 57.5f, 531.5f, 183f });
        headerTable.setLockedWidth(true);

    } catch (DocumentException ex) {
        Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex);
    }

    Image image = Image.getInstance(getClass().getClassLoader().getResource("img/sust.jpg"));
    image.scalePercent(42f);
    image.setAlignment(Element.ALIGN_LEFT);
    PdfPCell imageCell = new PdfPCell(image, false);
    imageCell.setPaddingTop(6);
    imageCell.setBorder(Rectangle.NO_BORDER);
    headerTable.addCell(imageCell);

    //start info table.....
    PdfPTable infoTable = new PdfPTable(1);
    infoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    String universityText = "SHAHJALAL UNIVERSITY OF SCIENCE & TECHNOLOGY SYLHET, BANGLADESH";
    String tabulationText = "TABULATION SHEET";
    String deptText = inputs.get(0).trim();

    String s1 = inputs.get(1).trim();
    String s2 = inputs.get(2).trim();
    String semesterText = ("B.Sc (Engg.) " + s1 + " SEMESTER EXAMINATION " + s2);

    String session = inputs.get(3).trim();
    String date = inputs.get(4).trim();

    String sessionDateText = ("SESSION:" + session + " EXAMINATION HELD IN: " + date);

    infoTable.addCell(getCellForHeaderString(universityText, 0, false, 0, Element.ALIGN_CENTER, font10, true));
    infoTable.addCell(getCellForHeaderString(tabulationText, 0, false, 0, Element.ALIGN_CENTER, font10, false));
    infoTable.addCell(getCellForHeaderString(deptText, 0, false, 0, Element.ALIGN_CENTER, font10, false));
    infoTable.addCell(getCellForHeaderString(semesterText, 0, false, 0, Element.ALIGN_CENTER, font10, false));
    infoTable
            .addCell(getCellForHeaderString(sessionDateText, 0, false, 0, Element.ALIGN_CENTER, font10, false));
    //end info table.....

    PdfPCell infoCell = new PdfPCell(infoTable);
    infoCell.setBorder(Rectangle.NO_BORDER);
    headerTable.addCell(infoCell);

    PdfPCell resultPublishDateCell = new PdfPCell(
            new Paragraph("Result Published On............................",
                    new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
    resultPublishDateCell.setBorder(Rectangle.NO_BORDER);
    resultPublishDateCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    resultPublishDateCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    headerTable.addCell(resultPublishDateCell);
    headerTable.setSpacingAfter(17.5f);
    // System.err.println("completed header table");
    return headerTable;
    //end creating header for the document......
}

From source file:fxml.test.PDFService.java

public PdfPTable createFooter1() {

    //String[] names = new String[]{"Md. Eamin Rahman", "Md. Mujibur Rahman", "Md Masum", "Md. Saiful Islam", "Husne Ara Chowdhury", "Sabir Ismail"};
    PdfPTable table = new PdfPTable(5);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);

    try {/*  w ww . j  a va 2  s.  c  om*/
        table.setTotalWidth(new float[] { 161f, 161f, 133f, 167f, 161f });
        table.setLockedWidth(true);

    } catch (DocumentException ex) {
        Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex);
    }
    //table.setWidthPercentage(100);
    PdfPCell chairmanSIgnature = new PdfPCell(new Paragraph("Signature of the Chairman:", font9));
    chairmanSIgnature.setBorder(Rectangle.NO_BORDER);
    chairmanSIgnature.setPaddingLeft(0f);
    chairmanSIgnature.setPaddingTop(5);
    table.addCell(chairmanSIgnature);

    PdfPCell underLine = new PdfPCell(new Paragraph("_______________________"));
    underLine.setBorder(Rectangle.NO_BORDER);
    table.addCell(underLine);

    PdfPCell blankColumn = new PdfPCell(new Paragraph(" "));
    blankColumn.setBorder(Rectangle.NO_BORDER);
    table.addCell(blankColumn);

    Paragraph p = new Paragraph("Signature of The Controller of Examinations:", font9);
    p.setLeading(0, 1.3f);
    PdfPCell controllerSignature = new PdfPCell();
    controllerSignature.addElement(p);
    controllerSignature.setBorder(Rectangle.NO_BORDER);
    table.addCell(controllerSignature);
    table.addCell(underLine);

    PdfPCell cell1 = new PdfPCell(new Paragraph(inputs.get(5).trim(), font9));
    cell1.setPaddingTop(0f);
    cell1.setBorder(Rectangle.NO_BORDER);

    PdfPCell cell2 = new PdfPCell(new Paragraph(inputs.get(6).trim(), font9));
    cell2.setPaddingTop(0f);
    cell2.setBorder(Rectangle.NO_BORDER);

    PdfPCell nameColumn = new PdfPCell(new Paragraph("Name :", font9));
    nameColumn.setBorder(Rectangle.NO_BORDER);
    nameColumn.setPaddingLeft(0f);
    nameColumn.setPaddingTop(0f);

    PdfPCell nameColumn2 = new PdfPCell(new Paragraph("Name :", font9));
    nameColumn2.setBorder(Rectangle.NO_BORDER);
    nameColumn2.setPaddingTop(0f);

    table.addCell(nameColumn);
    table.addCell(cell1);
    table.addCell(blankColumn);
    table.addCell(nameColumn2);
    table.addCell(cell2);

    table.setSpacingAfter(23.5f);
    return table;
}

From source file:fxml.test.PDFService.java

public PdfPTable createFooter2() {

    PdfPTable table = new PdfPTable(8);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);

    try {/*from ww  w  . j  av a 2  s . co  m*/
        table.setTotalWidth(new float[] { 192f, 144f, 5f, 144f, 5f, 144f, 5f, 144f });
        table.setLockedWidth(true);

    } catch (DocumentException ex) {
        Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex);
    }

    PdfPCell underLine = new PdfPCell(new Paragraph("_____________________"));
    underLine.setBorder(Rectangle.NO_BORDER);

    PdfPCell blankColumn = new PdfPCell(new Paragraph(" "));
    blankColumn.setBorder(Rectangle.NO_BORDER);

    PdfPCell blankColumn2 = new PdfPCell(new Paragraph(" "));
    blankColumn2.setBorder(Rectangle.BOTTOM);

    PdfPCell nameColumn = new PdfPCell(new Paragraph("Name :", font9));
    nameColumn.setBorder(Rectangle.NO_BORDER);
    nameColumn.setPaddingLeft(0f);

    PdfPCell cell3 = new PdfPCell(new Paragraph(inputs.get(7).trim(), font9));
    cell3.setPaddingRight(2);
    cell3.setBorder(Rectangle.TOP);

    PdfPCell cell4 = new PdfPCell(new Paragraph(inputs.get(8).trim(), font9));
    cell4.setBorder(Rectangle.TOP);

    PdfPCell cell5 = new PdfPCell(new Paragraph(inputs.get(9).trim(), font9));
    cell5.setBorder(Rectangle.TOP);

    PdfPCell cell6 = new PdfPCell(new Paragraph(inputs.get(10).trim(), font9));
    cell6.setBorder(Rectangle.TOP);

    PdfPCell memberSignature = new PdfPCell(new Paragraph("Signature of the Members:", font9));
    memberSignature.setPaddingLeft(0f);
    memberSignature.setBorder(Rectangle.NO_BORDER);

    table.addCell(memberSignature);
    table.addCell(blankColumn);
    table.addCell(blankColumn);
    table.addCell(blankColumn);
    table.addCell(blankColumn);
    table.addCell(blankColumn);
    table.addCell(blankColumn);
    table.addCell(blankColumn);

    table.addCell(nameColumn);
    table.addCell(cell3);
    table.addCell(blankColumn);
    table.addCell(cell4);
    table.addCell(blankColumn);
    table.addCell(cell5);
    table.addCell(blankColumn);
    table.addCell(cell6);

    PdfPCell tabulatorSignature = new PdfPCell(new Paragraph("Signature of the Tabulators:", font9));
    tabulatorSignature.setPaddingLeft(0f);
    tabulatorSignature.setPaddingTop(13f);
    tabulatorSignature.setBorder(Rectangle.NO_BORDER);

    table.addCell(tabulatorSignature);
    table.addCell(blankColumn2);
    table.addCell(blankColumn);
    table.addCell(blankColumn2);
    table.addCell(blankColumn);
    table.addCell(blankColumn2);
    table.addCell(blankColumn);
    table.addCell(blankColumn2);

    return table;

}

From source file:fxml.test.PDFService.java

public PdfPTable createTableHeader(int start) {

    PdfPTable table = null;

    try {/* w ww .  ja  v  a  2  s  .c om*/

        int colCount = 1;
        List<Float> columnsList = new ArrayList<>();

        columnsList.add(57.5f);
        columnsList.add(159.4f);

        for (int i = start; i < list.size(); i++) {

            if (list.get(i) instanceof Course) {

                columnsList.add(44f);

            } else if (list.get(i).equals("Total Credit")) {

                columnsList.add(30f);

            } else if (list.get(i).equals("Total GPA")) {

                columnsList.add(30f);

            } else if (list.get(i).equals("Letter Grade")) {

                columnsList.add(30f);

            } else if (list.get(i).equals("Cumulative")) {

                columnsList.add(88f);

            } else {

                columnsList.add(66f);

            }

            if (colCount == 12) {
                break;
            }
            colCount++;

        }

        float[] columns = new float[columnsList.size()];

        for (int i = 0; i < columnsList.size(); i++) {
            columns[i] = columnsList.get(i);
        }

        table = new PdfPTable(columns.length);

        System.err.println("table size :" + table.getNumberOfColumns());

        table.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.setTotalWidth(columns);
        table.setLockedWidth(true);

    } catch (DocumentException ex) {
        Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex);
    }

    PdfPCell regCell = getCellForString("Reg No.", 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9,
            false);
    regCell.setPaddingTop(0f);
    table.addCell(regCell);

    PdfPCell nameCell = getNameCell();
    nameCell.setPaddingBottom(2f);
    table.addCell(nameCell);

    int colCount = 1;

    for (int i = start; i < list.size(); i++) {

        if (list.get(i) instanceof Course) {

            Course course = (Course) list.get(i);

            PdfPCell cell3 = new PdfPCell(createCourseInfo(course));
            cell3.setPaddingTop(1f);
            cell3.setPaddingBottom(2f);
            //cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell3);

        } else if (list.get(i).equals("Total Credit") || list.get(i).equals("Total GPA")
                || list.get(i).equals("Letter Grade")) {

            String str = (String) list.get(i);
            String s[] = str.split(" ");

            PdfPTable totalCredit = new PdfPTable(1);
            totalCredit.setSpacingBefore(12.5f);
            totalCredit.setWidthPercentage(100);
            totalCredit.getDefaultCell().setBorder(Rectangle.NO_BORDER);

            PdfPCell cell1 = getCellForString(s[0], 0, false, 0, Element.ALIGN_CENTER,
                    new Font(Font.FontFamily.TIMES_ROMAN, 10f), false);
            PdfPCell cell2 = getCellForString(s[1], 0, false, 0, Element.ALIGN_CENTER,
                    new Font(Font.FontFamily.TIMES_ROMAN, 10f), false);

            totalCredit.addCell(cell1);
            totalCredit.addCell(cell2);

            PdfPCell grade = new PdfPCell(totalCredit);
            table.addCell(grade);

        } else if (list.get(i).equals("Cumulative")) {

            PdfPTable cumulative = new PdfPTable(1);
            // cumulative.setPaddingTop(count);
            cumulative.addCell(getCellForString("Cumulative", 0, false, Element.ALIGN_MIDDLE,
                    Element.ALIGN_CENTER, font10, true));

            PdfPTable creditGpaGrade = new PdfPTable(3);

            creditGpaGrade.setTotalWidth(88f);
            creditGpaGrade.setLockedWidth(true);
            creditGpaGrade.addCell(getCellForString("Credit", 0, false, Element.ALIGN_MIDDLE,
                    Element.ALIGN_CENTER, font10, true));
            creditGpaGrade.addCell(getCellForString("GPA", 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER,
                    font10, true));
            creditGpaGrade.addCell(getCellForString("Grade", 0, false, Element.ALIGN_MIDDLE,
                    Element.ALIGN_CENTER, font10, true));

            PdfPTable p = new PdfPTable(1);
            PdfPCell cell1 = new PdfPCell(cumulative);
            cell1.setPaddingBottom(3f);
            cell1.setBorder(Rectangle.NO_BORDER);
            PdfPCell cell2 = new PdfPCell(creditGpaGrade);
            cell2.setBorder(Rectangle.NO_BORDER);
            p.addCell(cell1);
            p.addCell(cell2);
            table.addCell(p);

        } else {

            table.addCell(getCellForString((String) list.get(i), 0, true, Element.ALIGN_MIDDLE,
                    Element.ALIGN_CENTER, font9, true));

        }

        if (colCount == 12) {
            break;
        }
        colCount++;
    }

    return table;

}

From source file:fxml.test.PDFService.java

private PdfPTable createTableBody(int studentStart, int start, PdfPTable table) {

    int studentCount = 1;

    for (int j = studentStart; j < studentList.size(); j++) {

        Student student = (Student) studentList.get(j);

        PdfPCell regCell = getCellForString(student.getRegNo(), 0, true, Element.ALIGN_MIDDLE,
                Element.ALIGN_CENTER, font9, false);
        regCell.setPaddingTop(2f);/*from w w w  . j a  v  a2s. com*/
        regCell.setPaddingBottom(3.85f);

        PdfPCell nameCell = getCellForString(student.getName(), 0, true, Element.ALIGN_MIDDLE, 0, font9, false);
        nameCell.setPaddingTop(1f);
        nameCell.setPaddingBottom(3.85f);
        nameCell.setPaddingLeft(5f);

        table.addCell(regCell);
        table.addCell(nameCell);

        int colCount = 1;

        //Getting student regestered courses for current semester.
        Map<String, CourseReg> regesteredCourse = student.getRegesteredCourse();

        for (int k = start; k < list.size(); k++) {

            //checking if its a instance of Course then we will print the Course details
            if (list.get(k) instanceof Course) {

                Course course = (Course) list.get(k);

                if (regesteredCourse.containsKey(course.getCourseCode())) {

                    CourseReg courseReg = regesteredCourse.get(course.getCourseCode());

                    PdfPTable table1 = new PdfPTable(2);
                    table1.setTotalWidth(44f);
                    table1.setLockedWidth(true);

                    PdfPCell cell1 = getCellForString(String.format("%.02f", courseReg.getGpa()), 0, false,
                            Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false);
                    cell1.setPaddingTop(1f);
                    cell1.setPaddingBottom(4f);

                    PdfPCell cell2 = getCellForString(courseReg.getLetterGrade(), 0, false,
                            Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false);
                    cell2.setPaddingTop(1f);
                    cell2.setPaddingBottom(4f);

                    table1.addCell(cell1);
                    table1.addCell(cell2);

                    PdfPCell cell3 = new PdfPCell(table1);
                    cell3.setPaddingTop(0f);
                    cell3.setPaddingBottom(0f);
                    table.addCell(cell3);

                } else {
                    table.addCell(new PdfPCell());
                }
            } //End checking if its a instance of Course then we will print the Course details
            else if (list.get(k).equals("Total Credit")) {

                PdfPCell creditCell = getCellForString(String.valueOf(student.getTotalCredit()), 0, true,
                        Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false);
                creditCell.setPaddingTop(1f);
                creditCell.setPaddingBottom(4f);
                table.addCell(creditCell);

            } else if (list.get(k).equals("Total GPA")) {

                PdfPCell gpaCell = getCellForString(String.format("%.02f", student.getGpa()), 0, true,
                        Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false);
                gpaCell.setPaddingTop(1f);
                gpaCell.setPaddingBottom(4f);
                table.addCell(gpaCell);

            } else if (list.get(k).equals("Letter Grade")) {

                PdfPCell gradeCell = getCellForString(student.getLetterGrade(), 0, true, Element.ALIGN_MIDDLE,
                        Element.ALIGN_CENTER, font9, false);
                gradeCell.setPaddingTop(1f);
                gradeCell.setPaddingBottom(4f);
                table.addCell(gradeCell);

            } else if (list.get(k).equals("Cumulative")) {

                PdfPTable table1 = new PdfPTable(3);
                table1.setTotalWidth(88f);
                table1.setLockedWidth(true);

                PdfPCell cell1 = getCellForString(String.format("%.02f", student.getCumulativeCredit()), 0,
                        true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false);
                cell1.setPaddingTop(1f);
                cell1.setPaddingBottom(4f);

                PdfPCell cell2 = getCellForString(String.format("%.02f", student.getCumulativeGpa()), 0, true,
                        Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false);
                cell2.setPaddingTop(1f);
                cell2.setPaddingBottom(4f);

                PdfPCell cell3 = getCellForString(student.getCumulativeLetterGrade(), 0, true,
                        Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false);
                cell3.setPaddingTop(1f);
                cell3.setPaddingBottom(4f);

                table1.addCell(cell1);
                table1.addCell(cell2);
                table1.addCell(cell3);

                PdfPCell cell4 = new PdfPCell(table1);
                cell4.setPaddingTop(0f);
                cell4.setPaddingBottom(0f);
                table.addCell(cell4);

            } else {

                table.addCell(new PdfPCell());

            }

            if (colCount == 12) {
                break;
            }
            colCount++;

        }

        if (studentCount == 15) {
            break;
        }
        studentCount++;

    }

    return table;
}

From source file:gov.utah.dts.det.ccl.documents.reporting.reports.CaseloadReport.java

@Override
public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor descriptor)
        throws TemplateException {
    List<Object[]> results = getResults(context);

    ColumnType columnType = ColumnType.valueOf((String) context.get(COLUMN_TYPE_KEY));
    RoleType roleType = RoleType.valueOf((String) context.get(SPECIALIST_TYPE_KEY));

    ReportTable<Integer> reportTable = new ReportTable<Integer>();

    for (Object[] res : results) {
        String column = null;//from   w ww . j  av  a 2 s . co m
        switch (columnType) {
        case LICENSE_TYPE:
            column = (String) res[3];
            break;
        case CITY:
            column = (String) res[3];
            break;
        case COUNTY:
            column = locationService.getCounty((String) res[3], (String) res[4], (String) res[5]);
            break;
        case ZIP_CODE:
            String zip = (String) res[5];
            if (zip.length() > 5) {
                zip = zip.substring(0, 5);
            }
            column = zip;
            break;
        }

        if (StringUtils.isBlank(column)) {
            column = "Unknown";
        }

        reportTable.addColumn(column);

        String specRow = null;
        String specFnm = (String) res[1];
        String specLnm = (String) res[2];
        if (StringUtils.isNotBlank(specFnm) || StringUtils.isNotBlank(specLnm)) {
            PersonalName name = new PersonalName(specFnm, specLnm);
            specRow = name.getFirstAndLastName();
        } else {
            specRow = "Unknown";
        }

        reportTable.addRow(specRow);

        Integer val = reportTable.getTableDataItem(specRow, column);
        if (val == null) {
            val = new Integer(1);
        } else {
            val = new Integer(val.intValue() + 1);
        }
        reportTable.addTableDataItem(specRow, column, val);
    }

    setFileName(context, descriptor);

    Document document = new Document(PAGE_SIZE, MARGIN, MARGIN, MARGIN, MARGIN);
    try {
        PdfWriter canvas = PdfWriter.getInstance(document, outputStream);
        document.open();

        ColumnText text = new ColumnText(canvas.getDirectContent());
        text.setSimpleColumn(document.getPageSize().getLeft(MARGIN), document.getPageSize().getBottom(MARGIN),
                document.getPageSize().getRight(MARGIN), document.getPageSize().getTop(MARGIN));

        StringBuilder sb = new StringBuilder(roleType.getDisplayName());
        sb.append(" Caseloads");
        Paragraph heading = new Paragraph(sb.toString(), REPORT_HEADING_FONT);
        heading.setAlignment(Element.ALIGN_CENTER);
        text.addElement(heading);
        text.go();
        float yLine = text.getYLine();
        yLine -= FONT_SIZE;

        int columns = reportTable.getColumns().size() + 2;

        String[][] totTab = new String[reportTable.getRows().size()][columns];
        float maxLicWidth = 0f;
        float maxTotWidth = FONT_SIZE;
        int rowIdx = 0;
        for (Iterator<String> rowItr = reportTable.getRows().iterator(); rowItr.hasNext();) {
            String row = rowItr.next();
            totTab[rowIdx][0] = row;
            float licWidth = getTextWidth(row, FONT);
            if (licWidth > maxLicWidth) {
                maxLicWidth = licWidth;
            }

            int rowTotal = 0;
            int colIdx = 1;
            for (Iterator<String> colItr = reportTable.getColumns().iterator(); colItr.hasNext();) {
                String col = colItr.next();
                Integer val = reportTable.getTableDataItem(row, col);
                if (val != null) {
                    totTab[rowIdx][colIdx] = val.toString();
                    rowTotal += val.intValue();
                }
                colIdx++;
            }
            String rowTotalStr = Integer.toString(rowTotal);
            float totWidth = getTextWidth(rowTotalStr, TABLE_HEADER_FONT);
            if (totWidth > maxTotWidth) {
                maxTotWidth = totWidth;
            }
            totTab[rowIdx][columns - 1] = rowTotalStr;
            rowIdx++;
        }

        //add border and cell padding to licensor width
        maxLicWidth += (TABLE_CELL_PADDING * 2) + (TABLE_BORDER_SIZE * 2);
        maxTotWidth += (TABLE_CELL_PADDING * 2) + (TABLE_BORDER_SIZE * 2);

        float width = PAGE_SIZE.getWidth() - (2 * MARGIN);
        width -= maxLicWidth;

        float[] colWidths = new float[columns];
        colWidths[0] = maxLicWidth;
        for (int i = 1; i < columns; i++) {
            colWidths[i] = maxTotWidth;
        }

        PdfPTable table = new PdfPTable(reportTable.getColumns().size() + 2);
        table.setHeaderRows(1);
        table.setLockedWidth(true);
        table.setTotalWidth(colWidths);
        table.setSpacingBefore(FONT_SIZE);
        setDefaultCellAttributes(table.getDefaultCell());

        PdfPCell cell = null;

        cell = new PdfPCell(new Phrase(""));
        cell.setBorderWidthTop(0);
        cell.setBorderWidthLeft(0);
        table.addCell(cell);
        for (Iterator<String> itr = reportTable.getColumns().iterator(); itr.hasNext();) {
            cell = getRotatedHeaderCell(itr.next());
            table.addCell(cell);
        }
        cell = getRotatedHeaderCell("Total");
        table.addCell(cell);

        for (String[] row : totTab) {
            for (int i = 0; i < row.length; i++) {
                if (row[i] == null) {
                    table.addCell(getNumberCell(""));
                } else {
                    table.addCell(getCell(new Phrase(row[i], i == row.length - 1 ? TABLE_HEADER_FONT : FONT),
                            i == 0 ? Element.ALIGN_LEFT : Element.ALIGN_CENTER));
                }

            }
        }

        writeTable(table, document, canvas.getDirectContent(), colWidths, yLine, true);
    } catch (DocumentException de) {
        throw new TemplateException(de);
    }
    document.close();
}

From source file:ihm.panneaux.GenererPdf.java

private void initComponement() throws FileNotFoundException, DocumentException, IOException {
    String DEST = "devis/devis-" + devis.getNumero() + ".pdf";
    OutputStream file = new FileOutputStream(new File(DEST));

    com.itextpdf.text.Document document = new com.itextpdf.text.Document();
    PdfWriter.getInstance((com.itextpdf.text.Document) document, file);
    // PAS TOUCHE
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST));

    Rectangle rect = new Rectangle(30, 30, 550, 800);
    writer.setBoxSize("art", rect);
    HeaderFooterPageEvent event = new HeaderFooterPageEvent();
    writer.setPageEvent(event);/*from ww  w  . j  av a 2s.c om*/
    document.open();
    PdfContentByte canvas = writer.getDirectContent();

    Image logo = Image.getInstance("images/logo.png");
    logo.scaleAbsolute(200, 57);

    // INFO DEVIS
    Image devisImg = Image.getInstance("images/imgDevis.png");
    devisImg.scaleAbsolute(110, 34);
    devisImg.setAbsolutePosition((PageSize.POSTCARD.getWidth() + 150),
            (PageSize.POSTCARD.getHeight() - devisImg.getScaledHeight()) * 2);
    Font fontImgDevis = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    Phrase numeroInfo = new Phrase("Numro  " + devis.getNumero(), fontImgDevis);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, numeroInfo, devisImg.getScaledWidth() + 413,
            devisImg.getScaledHeight() + 710, 0);
    Phrase dateInfo = new Phrase("Le  " + devis.getDate(), fontImgDevis);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, dateInfo, devisImg.getScaledWidth() + 420,
            devisImg.getScaledHeight() + 695, 0);
    Image devisImgBordure = Image.getInstance("images/bordureDevis.png");
    devisImgBordure.setAbsolutePosition((devisImg.getScaledWidth() + 318), devisImg.getScaledHeight() + 660);
    devisImgBordure.scaleAbsolute(120, 122);

    // INFO ENTREPRISE
    Font fontEntreprise = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.BOLD);
    Phrase coGerants = new Phrase("Co-grants : " + devis.getEntreprise().getCoGerant(), fontEntreprise);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, coGerants, devisImg.getScaledWidth() + 210,
            devisImg.getScaledHeight() + 660, 0);
    Phrase siege = new Phrase("Sige : " + devis.getEntreprise().getSiege(), fontEntreprise);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, siege, devisImg.getScaledWidth() + 149,
            devisImg.getScaledHeight() + 640, 0);
    Phrase tel = new Phrase("TEL : " + devis.getEntreprise().getTel(), fontEntreprise);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, tel, devisImg.getScaledWidth() + 113,
            devisImg.getScaledHeight() + 625, 0);
    Image bordureEntreprise = Image.getInstance("images/bordureEntreprise.png");
    bordureEntreprise.setAbsolutePosition(devisImg.getScaledWidth() - 80, devisImg.getScaledHeight() + 610);

    // INFO CLIENT
    Font fontClient = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL);
    Phrase nomPrenom = new Phrase(devis.getClient().getNom() + " " + devis.getClient().getPrenom(), fontClient);
    Phrase commune = new Phrase(devis.getClient().getAdresse(), fontClient);
    Phrase adresse = new Phrase(devis.getClient().getCodePostale() + " " + devis.getClient().getCommune(),
            fontClient);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, nomPrenom, PageSize.A4.getWidth() - 280,
            devisImg.getScaledHeight() + 595, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, commune, PageSize.A4.getWidth() - 280,
            devisImg.getScaledHeight() + 580, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, adresse, PageSize.A4.getWidth() - 280,
            devisImg.getScaledHeight() + 565, 0);

    document.add(logo);
    document.add(devisImg);
    document.add(devisImgBordure);
    document.add(bordureEntreprise);

    // AJOUT DES DONNEES DU TABLEAUX 

    float[] columnWidths = { 14, 3, 4, 3, 4 };
    Font fontCategorie = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    fontCategorie.setColor(BaseColor.GREEN);

    PdfPTable table = new PdfPTable(columnWidths);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    table.setTotalWidth(PageSize.A4.getWidth() - 15);

    table.setSpacingBefore(150);

    table.setLockedWidth(true);

    Font Categorie = new Font(FontFamily.HELVETICA, 13, Font.BOLD);
    Font Chantier = new Font(FontFamily.HELVETICA, 11, Font.UNDERLINE);

    PdfPCell cellChantier = new PdfPCell(new Phrase("CHANTIER : " + chantier, Chantier));
    cellChantier.setColspan(3);
    cellChantier.setBorder(Rectangle.NO_BORDER);
    table.addCell(cellChantier);
    table.addCell(" ");
    table.addCell(" ");

    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");

    table.addCell(new Phrase("Dsignation", Categorie));
    PdfPCell unite = new PdfPCell(new Phrase("Unite", Categorie));
    PdfPCell quantite = new PdfPCell(new Phrase("Quantite", Categorie));
    PdfPCell prixht = new PdfPCell(new Phrase("Prix HT", Categorie));
    PdfPCell pvtht = new PdfPCell(new Phrase("Pvt HT", Categorie));

    unite.setHorizontalAlignment(Element.ALIGN_CENTER);
    quantite.setHorizontalAlignment(Element.ALIGN_CENTER);
    prixht.setHorizontalAlignment(Element.ALIGN_CENTER);
    pvtht.setHorizontalAlignment(Element.ALIGN_CENTER);

    unite.setBorder(Rectangle.NO_BORDER);
    quantite.setBorder(Rectangle.NO_BORDER);
    prixht.setBorder(Rectangle.NO_BORDER);
    pvtht.setBorder(Rectangle.NO_BORDER);

    table.addCell(unite);
    table.addCell(quantite);
    table.addCell(prixht);
    table.addCell(pvtht);

    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");

    double htTotalParcour = 0;
    double ttcTotalParcour = 0;

    if (this.EquipementDeChantier.isEmpty() == false) {
        table.addCell(new Phrase("Equipement De Chantier", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");

        for (DevisContenu listeMaterielDevi : EquipementDeChantier) {

            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            /* BACKUP
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            table.addCell(listeMaterielDevi.getMateriel().getUnite());
            table.addCell(Double.toString(listeMaterielDevi.getQuantite()));
            table.addCell(Double.toString(listeMaterielDevi.getMateriel().getPrix())+"");
            table.addCell(Double.toString(listeMaterielDevi.getPvtHT())+"");
            */
            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (Couverture.isEmpty() == false) {
        table.addCell(new Phrase("Couverture", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Couverture) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (CouvertureArdoise.isEmpty() == false) {
        table.addCell(new Phrase("Couverture Ardoise", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : CouvertureArdoise) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (CouvertureTuile.isEmpty() == false) {
        table.addCell(new Phrase("Couverture Tuile", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : CouvertureTuile) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (this.Demoussage.isEmpty() == false) {
        table.addCell(new Phrase("Demoussage", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Demoussage) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");

    }
    if (this.Velux.isEmpty() == false) {
        table.addCell(new Phrase("Velux", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Velux) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");

    }
    if (this.Zinguerie.isEmpty() == false) {
        table.addCell(new Phrase("Zinguerie", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Zinguerie) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (Plancher.isEmpty() == false) {
        table.addCell(new Phrase("Plancher", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Plancher) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }

    ttcTotalParcour = (ttcTotalParcour * devis.getTva() / 100) + ttcTotalParcour;

    LineDash solid = new SolidLine();
    PdfPCell cell, cell2, cellSOUSTOTAL, cellhttotal, tva, getTva, totalttc, gettotalttc;

    table.addCell(new Phrase(" "));
    table.addCell(new Phrase(" "));
    table.addCell(new Phrase(" "));
    table.addCell(new Phrase(" "));

    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setCellEvent(new CustomBorder(null, null, null, solid));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    table.addCell(new Phrase(""));
    table.addCell(new Phrase(""));
    cellSOUSTOTAL = new PdfPCell(new Phrase("SOUS-TOTAL"));
    cellSOUSTOTAL.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    cellSOUSTOTAL.setBorder(Rectangle.NO_BORDER);
    table.addCell(cellSOUSTOTAL);
    table.addCell(new Phrase(""));
    double prixHT_2Chiffre = Math.round((htTotalParcour) * Math.pow(10, 2)) / Math.pow(10, 2);
    String httotal = String.valueOf(prixHT_2Chiffre);
    cellhttotal = new PdfPCell(new Phrase(httotal + ""));
    cellhttotal.setBorder(Rectangle.NO_BORDER);
    cellhttotal.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cellhttotal);

    table.addCell(new Phrase(""));
    table.addCell(new Phrase(""));
    tva = new PdfPCell(new Phrase("TVA"));
    tva.setBorder(Rectangle.NO_BORDER);
    tva.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(tva);

    getTva = new PdfPCell(new Phrase(devis.getTva() + "%"));
    getTva.setBorder(Rectangle.NO_BORDER);
    getTva.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(getTva);

    String tvaprix = String.valueOf(htTotalParcour * devis.getTva() / 100);
    double prixTVA_2Chiffre = Math.round(Double.parseDouble(tvaprix) * Math.pow(10, 2)) / Math.pow(10, 2);
    cell2 = new PdfPCell(new Phrase(Double.toString(prixTVA_2Chiffre) + ""));
    cell2.setBorder(PdfPCell.NO_BORDER);
    cell2.setCellEvent(new CustomBorder(null, null, null, solid));
    cell2.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell2);

    table.addCell("");
    table.addCell("");
    totalttc = new PdfPCell(new Phrase("Total TTC"));
    totalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    totalttc.setBorder(PdfPCell.NO_BORDER);
    table.addCell(totalttc);
    table.addCell("");
    double prixTTC_2Chiffre = Math.round(ttcTotalParcour * Math.pow(10, 2)) / Math.pow(10, 2);
    String ttctotal = String.valueOf(Double.toString(prixTTC_2Chiffre));
    gettotalttc = new PdfPCell(new Phrase(ttctotal + ""));
    gettotalttc.setBorder(PdfPCell.NO_BORDER);
    gettotalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(gettotalttc);

    table.setSpacingAfter(10);

    document.add(table);

    Pattern p = Pattern.compile("[.^\\.]+");
    String texte = devis.getInformationComplementaire();

    Font infoComptBlue = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL);
    infoComptBlue.setColor(BaseColor.BLUE);
    Font infoComptRed = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL);
    infoComptRed.setColor(BaseColor.RED);
    Font infoComptBlack = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL);
    infoComptBlack.setColor(BaseColor.BLACK);

    Paragraph infoComp = new Paragraph();
    Image BonPourAccord = null;
    BonPourAccord = Image.getInstance("images/BonPourAccord.png");
    infoComp.setAlignment(Element.ALIGN_LEFT);
    BonPourAccord.setAlignment(Image.TEXTWRAP | Image.ALIGN_RIGHT);

    String[] phrase = p.split(texte);
    for (int i = 0; i < phrase.length; i++) {
        if (i == 0 || i == 1) {
            infoComp.add(new Paragraph(phrase[i], infoComptBlue));
        }
        if (i == 2 || i == 3 || i == 4 || i == 5) {
            infoComp.add(new Paragraph(phrase[i], infoComptRed));

        }
        if (i > 5 && i <= 11)
            infoComp.add(new Paragraph(phrase[i], infoComptBlack));
        if (i > 11)
            infoComp.add(new Paragraph(phrase[i], infoComptRed));
    }
    /* A OPTIMISER */

    float taille_tableau = table.calculateHeights() + table.getRowHeight(table.getLastCompletedRowIndex());

    if (taille_tableau > 386) {
        document.newPage();
    }
    document.add(BonPourAccord);
    document.add(infoComp);

    document.close();

    EnvoieDevis envoie = new EnvoieDevis(null, true, session, devis);
    this.CouvertureArdoise.clear();
    this.CouvertureTuile.clear();
    this.Demoussage.clear();
    this.EquipementDeChantier.clear();
    this.Velux.clear();
    this.Zinguerie.clear();
    this.Couverture.clear();
    this.Plancher.clear();
}

From source file:lk.score.androphsy.report.ReportPdf.java

License:Open Source License

private void CreateTable(Paragraph subpara, String feature) {
    System.out.println("Report Create Table: " + feature);
    try {/*from  www .  j  a v a  2s  . co m*/
        String query = "";
        Connection conn = new ConnectDb().getConnection();
        Statement stmt = conn.createStatement();

        if (feature == "PRIMARY_ACC") {
            query = "SELECT host AS 'Account Type', username AS 'User Name',"
                    + " password AS 'Password (HASHED)'" + " FROM Androspy_Account" + " WHERE case_id = "
                    + AndrospyMain.gb_CaseId + " AND device_id = " + AndrospyMain.gb_DeviceId
                    + " AND primary_acc = " + 1;

        } else if (feature == "OTHER_ACC") {
            query = "SELECT host AS 'Account Type', username AS 'User Name'," + " password AS 'Password'"
                    + " FROM Androspy_Account" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId + " AND primary_acc != " + 1;

        } else if (feature == "SMS") {
            query = "SELECT subject AS 'Subject', body AS 'Message Body',"
                    + " type AS 'Message Type', date_received AS 'Received Date', date_sent AS 'Send Date'"
                    + " FROM Sms" + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId;

        } else if (feature == "Phone Book") {
            query = "SELECT contact_no AS 'Contact No', name AS 'Name',"
                    + " times_contacted AS 'Times Contacted', last_time_contacted AS 'Last Contacted Date'"
                    + " FROM Contacts" + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId;

        } else if (feature == "Gmail") {
            query = "SELECT fromaddress AS 'From Address',"
                    + " toaddress AS 'To Address', ccaddress AS 'CC Address', bccaddress AS 'BCC Address',"
                    + " replytoaddress AS 'Reply To Address', subject AS 'Subject', snippet As 'Message Body', "
                    + "datesent AS 'Send Date', datereceive AS 'Received Date'" + " FROM Gmail_Store"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId;

        } else if (feature == "Calendar") {
            query = "SELECT title AS 'Title', description AS 'Event', location AS 'Location',"
                    + " start_time AS 'Start Time', end_time AS 'End Time', created_by AS 'Creator'"
                    + " FROM Calendar_Event" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId;

        } else if (feature == "YouTube") {
            query = "SELECT query AS 'Search' , search_date AS 'Time Stamp'" + " FROM Youtube_History"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId;

        } else if (feature.equals("FACEBOOK_MESSAGES")) {
            query = "SELECT IFNULL(sender, '') AS 'Sender'," + " IFNULL(text, '') AS 'Message',"
                    + " IFNULL(conversation_date, '') AS 'Date'," + " IFNULL(logitude, '') AS 'Longitude',"
                    + " IFNULL(latitude, '') AS 'Latitude'" + " FROM Facebook_Message" + " WHERE case_id = "
                    + AndrospyMain.gb_CaseId + " AND device_id = " + AndrospyMain.gb_DeviceId;

        } else if (feature.equals("FACEBOOK_CONTACTS")) {
            query = "SELECT IFNULL(first_name, '') AS 'First Name'," + " IFNULL(last_name, '') AS 'Last Name',"
                    + " IFNULL(display_name, '') AS 'Display Name',"
                    + " IFNULL(added_time, '') AS 'Time Stamp'," + " IFNULL(type, '') AS 'Contact Type'"
                    + " FROM Fb_Contacts" + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId;

        } else if (feature.equals("FACEBOOK_NOTIFICATIONS")) {
            query = "SELECT IFNULL(notification, '') AS 'Notification'," + " IFNULL(update_date, '') AS 'Date'"
                    + " FROM Facebook_Notifications" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId;

        } else if (feature.equals("LINKEDIN_PROFILE")) {
            query = "SELECT first_name AS 'First Name', last_name AS 'Last Name', display_name AS 'Display Name',"
                    + "country AS 'Country', join_date AS 'Join Date', connections AS 'No of Connections'"
                    + " FROM Linkedin_Profile" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId;

        } else if (feature.equals("LINKEDIN_CONNECTIONS")) {
            query = "SELECT IFNULL(first_name, '') AS 'First Name'," + " IFNULL(last_name, '') AS 'Last Name',"
                    + " IFNULL(display_name, '') AS 'Display Name'," + " IFNULL(title, '') AS 'Title'"
                    + " FROM Linkedin_Connections" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId;

        } else if (feature.equals("LINKEDIN_INVITATIONS")) {
            query = "SELECT IFNULL(from_display_name, '') AS 'Sender Name'," + " IFNULL(title, '') AS 'Title',"
                    + " IFNULL(invitation_date, '') AS 'Invitation Date'" + " FROM Linkedin_Invitation"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId;

        } else if (feature.equals("LINKEDIN_MESSAGES")) {
            query = "SELECT from_display_name AS 'Remote Party', from_title AS 'Remote Party Title',"
                    + " message_date AS 'Message Date', subject AS Subject, message_body AS Message"
                    + " FROM Linkedin_Message" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId;

        } else if (feature.equals("DEFAULT_BROWSER_HISTORY")) {
            query = "SELECT title AS Title, url AS URL, "
                    + "last_visit_date AS 'Last Visit Date', visits AS 'No of Visitis'"
                    + " FROM Browser_History" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId + " AND browser = 'DEFAULTB'";

        } else if (feature.equals("DEFAULT_BOOKMARKS")) {
            query = "SELECT title AS Title, url AS URL, "
                    + "created_date AS 'Creaded Date', modified_date AS 'Modified Date', deleted AS Deleted,"
                    + "account_name AS 'Created By', account_type AS 'Account Type'" + " FROM Androspy_Bookmark"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND browser = 'DEFAULTB'";

        } else if (feature.equals("DEFAULT_WEB_FORM_DATA")) {
            query = "SELECT url AS 'URL', name AS 'Parameter Name', value AS 'Parameter Value'"
                    + " FROM WebForm f, WebFormData d"
                    + " WHERE f.case_id = d.case_id AND f.device_id = d.device_id" + " AND d.urlid = f.id"
                    + " AND d.case_id = " + AndrospyMain.gb_CaseId + " AND d.device_id = "
                    + AndrospyMain.gb_DeviceId;

        } else if (feature.equals("DEFAULT_COOKIES")) {
            query = "SELECT host AS 'Host', "
                    + "cookie_name AS 'Cookie Name', cookie_value AS 'Cookie Value', path AS Path, "
                    + "secure AS Secure, httponly AS 'Http Only', created_date AS 'Created Date', "
                    + "expire_date AS 'Expire Date', last_access_date AS 'Last Access Date'"
                    + " FROM Browser_Cookies" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId + " AND browser = 'DEFAULTB'";

        } else if (feature.equals("DEFAULT_WEB_SEARCH")) {
            query = "SELECT search_text AS 'Search Text', " + "search_date AS 'Search Date'" + " FROM WebSearch"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND browser = 'DEFAULTB'";

        } else if (feature.equals("CHROME_BROWSER_HISTORY")) {
            query = "SELECT title AS Title, url AS URL, "
                    + "last_visit_date AS 'Last Visit Date', visits AS 'No of Visitis'"
                    + " FROM Browser_History" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId + " AND browser = 'CHROME'";

        } else if (feature.equals("CHROME_COOKIES")) {
            query = "SELECT host AS 'Host', "
                    + "cookie_name AS 'Cookie Name', cookie_value AS 'Cookie Value', path AS Path, "
                    + "secure AS Secure, httponly AS 'Http Only', created_date AS 'Created Date', "
                    + "expire_date AS 'Expire Date', last_access_date AS 'Last Access Date'"
                    + " FROM Browser_Cookies" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId + " AND browser = 'CHROME'";

        } else if (feature.equals("CHROME_WEB_SEARCH")) {
            query = "SELECT search_text AS 'Search Text', " + "search_date AS 'Search Date'" + " FROM WebSearch"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND browser = 'CHROME'";

        } else if (feature.equals("CHROME_CREDIT_CARD")) {
            query = "SELECT name AS Name, expire_month AS 'Expire Month', expire_year AS 'Exire Year', "
                    + "modified_date AS 'Modified Date'" + " FROM Browser_Credit_Card" + " WHERE case_id = "
                    + AndrospyMain.gb_CaseId + " AND device_id = " + AndrospyMain.gb_DeviceId
                    + " AND browser = 'CHROME'";

        } else if (feature.equals("Firefox_BROWSER_HISTORY")) {
            query = "SELECT title AS Title, url AS URL, "
                    + "last_visit_date AS 'Last Visit Date', visits AS 'No of Visitis'"
                    + " FROM Browser_History" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId + " AND browser = 'Firefox'";

        } else if (feature.equals("Firefox_BOOKMARKS")) {
            query = "SELECT title AS Title, url AS URL, "
                    + "created_date AS 'Creaded Date', modified_date AS 'Modified Date', deleted AS Deleted,"
                    + "account_name AS 'Created By', account_type AS 'Account Type'" + " FROM Androspy_Bookmark"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND browser = 'Firefox'";

        } else if (feature.equals("Firefox_WEB_SEARCH")) {
            query = "SELECT search_text AS 'Search Text', " + "search_date AS 'Search Date'" + " FROM WebSearch"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND browser = 'Firefox'";

        } else if (feature.equals("Firefox_COOKIES")) {
            query = "SELECT host AS 'Host', "
                    + "cookie_name AS 'Cookie Name', cookie_value AS 'Cookie Value', path AS Path, "
                    + "secure AS Secure, httponly AS 'Http Only', created_date AS 'Created Date', "
                    + "expire_date AS 'Expire Date', last_access_date AS 'Last Access Date'"
                    + " FROM Browser_Cookies" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId + " AND browser = 'Firefox'";

        } else if (feature == "ALL_CALL_LOG") {
            query = "SELECT contact_no AS 'Contact No', name AS 'Name',"
                    + " date AS 'Contacted Date', duration AS 'Call Duration', "
                    + "countryiso AS 'Country Code', geolocationcode AS 'Geo Location'" + " FROM Event_Log"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND logtype = " + 100;

        } else if (feature == "INCOMING_CALLS") {
            query = "SELECT contact_no AS 'Contact No', name AS 'Name',"
                    + " date AS 'Contacted Date', duration AS 'Call Duration', "
                    + "countryiso AS 'Country Code', geolocationcode AS 'Geo Location'" + " FROM Event_Log"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND logtype = " + 100 + " AND type = " + 1;

        } else if (feature == "MISSED_CALLS") {
            query = "SELECT contact_no AS 'Contact No', name AS 'Name',"
                    + " date AS 'Contacted Date', duration AS 'Call Duration', "
                    + "countryiso AS 'Country Code', geolocationcode AS 'Geo Location'" + " FROM Event_Log"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND logtype = " + 100 + " AND type = " + 3;

        } else if (feature == "CANCELLED_CALLS") {
            query = "SELECT contact_no AS 'Contact No', name AS 'Name',"
                    + " date AS 'Contacted Date', duration AS 'Call Duration', "
                    + "countryiso AS 'Country Code', geolocationcode AS 'Geo Location'" + " FROM Event_Log"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND logtype = " + 500;

        } else if (feature == "OUTGOING_CALLS") {
            query = "SELECT contact_no AS 'Contact No', name AS 'Name',"
                    + " date AS 'Contacted Date', duration AS 'Call Duration', "
                    + "countryiso AS 'Country Code', geolocationcode AS 'Geo Location'" + " FROM Event_Log"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND logtype = " + 100 + " AND type = " + 2;

        } else if (feature == "ALL_SMS_LOG") {
            query = "SELECT contact_no AS 'Contact No', name AS 'Name'," + " date AS 'Contacted Date', "
                    + "messageid AS 'Message_Id', m_subject AS 'Message Subject', m_content AS 'Message Body', "
                    + "countryiso AS 'Country Code', geolocationcode AS 'Geo Location'" + " FROM Event_Log"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND logtype = " + 300;

        } else if (feature == "SMS_INBOX") {
            query = "SELECT contact_no AS 'Contact No', name AS 'Name'," + " date AS 'Contacted Date', "
                    + "messageid AS 'Message_Id', m_subject AS 'Message Subject', m_content AS 'Message Body', "
                    + "countryiso AS 'Country Code', geolocationcode AS 'Geo Location'" + " FROM Event_Log"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND logtype = " + 300 + " AND type = " + 1;

        } else if (feature == "SMS_OUTBOX") {
            query = "SELECT contact_no AS 'Contact No', name AS 'Name'," + " date AS 'Contacted Date', "
                    + "messageid AS 'Message_Id', m_subject AS 'Message Subject', m_content AS 'Message Body', "
                    + "countryiso AS 'Country Code', geolocationcode AS 'Geo Location'" + " FROM Event_Log"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND logtype = " + 300 + " AND type != " + 1;

        } else if (feature == "ALL_MMS_LOG") {
            query = "SELECT contact_no AS 'Contact No', name AS 'Name'," + " date AS 'Contacted Date', "
                    + "messageid AS 'Message_Id', m_subject AS 'Message Subject', m_content AS 'Message Body', "
                    + "countryiso AS 'Country Code', geolocationcode AS 'Geo Location'" + " FROM Event_Log"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND logtype = " + 200;

        } else if (feature == "MMS_INBOX") {
            query = "SELECT contact_no AS 'Contact No', name AS 'Name'," + " date AS 'Contacted Date', "
                    + "messageid AS 'Message_Id', m_subject AS 'Message Subject', m_content AS 'Message Body', "
                    + "countryiso AS 'Country Code', geolocationcode AS 'Geo Location'" + " FROM Event_Log"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND logtype = " + 200 + " AND type = " + 1;

        } else if (feature == "MMS_OUTBOX") {
            query = "SELECT contact_no AS 'Contact No', name AS 'Name'," + " date AS 'Contacted Date', "
                    + "messageid AS 'Message_Id', m_subject AS 'Message Subject', m_content AS 'Message Body', "
                    + "countryiso AS 'Country Code', geolocationcode AS 'Geo Location'" + " FROM Event_Log"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId + " AND logtype = " + 200 + " AND type != " + 1;

        } else if (feature == "Wi-Fi Access Points") {
            query = "SELECT ssid AS 'SSID', password AS 'Password', key_mgmt AS 'Key Management'"
                    + " FROM Wifi_Info" + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId;

        } else if (feature.equals("Wi-Fi Access Points")) {
            query = "SELECT ssid AS 'SSID', password AS 'Password', key_mgmt AS 'Key Management'"
                    + " FROM Wifi_Info" + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId;

        } else if (feature == "BT_USED") {
            query = "SELECT device_address AS 'Target Device BT Address', mimetype AS 'MIME Type', "
                    + " in_file_name AS 'File Name', totalbytes AS 'File Size', location AS Location, direction AS Direction, visibility AS Visibility, confirm AS Confirm,"
                    + " status AS 'Transfer Status', date AS 'Transfer Date', scanned As Scanned"
                    + " FROM Bluetooth_Tranfer" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId;

        } else if (feature == "BT_SEEN") {
            query = "SELECT bmac AS 'Bluetooth Address',"
                    + " device_name AS 'Device Name', seen_date AS 'Last Seen Date', 'used_date' AS 'Last_Paired_Date'"
                    + " FROM Bluetooth_Device" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId;

        } else if (feature == "Skype Account") {
            System.out.println("Skype Account");
            query = "SELECT skypename, fullname, birthday, country, city reg_date, gender"
                    + " FROM Skype_Account" + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId;

        } else if (feature == "Skype Contacts") {
            System.out.println("Skype Contacts");
            query = "SELECT skypename, fullname, birthday, displayname, country, city, gender, phone"
                    + " FROM Skype_Contacts" + " WHERE case_id = " + AndrospyMain.gb_CaseId
                    + " AND device_id = " + AndrospyMain.gb_DeviceId;

        } else if (feature == "Skype Calls") {
            System.out.println("Skype Calls");
            query = "SELECT identity, display_name, call_duration, start_time_stamp" + " FROM Skype_Call"
                    + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId;

        } else if (feature == "Skype Messages") {
            System.out.println("Skype Messages");
            query = "SELECT author, from_display_name, dialog_partner, message, time_stamp"
                    + " FROM Skype_Message" + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = "
                    + AndrospyMain.gb_DeviceId;

        }

        if (query != ("")) {
            if (!bflagall) {
                query += " AND favourite = " + 1;
            }

            System.out.println("query: " + query);

            ResultSet rs = stmt.executeQuery(query);
            ResultSetMetaData rsmeta = rs.getMetaData();
            int colcount = rsmeta.getColumnCount();
            PdfPTable pdftable = new PdfPTable(colcount);
            pdftable.setWidthPercentage(100 / colcount);
            pdftable.setTotalWidth(527);
            pdftable.setLockedWidth(true);

            for (int i = 1; i <= colcount; i++) {
                PdfPCell c1 = new PdfPCell(new Phrase(rsmeta.getColumnLabel(i)));
                c1.setHorizontalAlignment(Element.ALIGN_CENTER);
                pdftable.addCell(c1);
            }
            pdftable.setHeaderRows(1);

            while (rs.next()) {
                for (int i = 1; i <= colcount; i++) {
                    System.out.println("add table cell report " + rs.getString(i));
                    pdftable.addCell(rs.getString(i));
                }
            }

            subpara.add(pdftable);
        }

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:Login.ventas.fproyectos.java

/**
 * Creates new form cliente// w  w  w  . j a v a 2  s. com
 * @param user
 */
public fproyectos(Login user) {
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    @SuppressWarnings("MismatchedReadAndWriteOfArray")
    String[] fecha = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre",
            "Octubre", "Noviembre", "Diciembre" };
    initComponents();
    Calendar rightNow = Calendar.getInstance();
    int ccyy = rightNow.get(Calendar.YEAR);
    int month = rightNow.get(Calendar.MONTH);
    setSize(d.width, d.height - 95);
    this.usuario = user;
    add(f);
    f.setLocation(jPanel1.getX(), jPanel1.getY());
    add(f3);
    f3.setLocation(jPanel1.getX(), jPanel1.getY());
    add(f4);
    f4.setLocation(jPanel1.getX(), jPanel1.getY());
    add(f5);
    f5.setLocation(jPanel1.getX(), jPanel1.getY());
    add(f2);
    f2.setLocation(jPanel1.getX(), jPanel1.getY());

    f2.getjButton1().addMouseListener(new java.awt.event.MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            try {
                ServiceHb helper = new ServiceHb();
                helper.iniciarTransaccion();
                Fcomisiones fc = helper.getFcomisiones(idcliente, idinstalacion);
                if (helper.getFcomisiones(idcliente, idinstalacion) == null) {
                    fc = new Fcomisiones();
                    Calendar d = Calendar.getInstance();
                    fc.setFecha(new java.sql.Date(d.getTime().getTime()));
                    fc.setClientes(
                            (Clientes) helper.obtenerObjeto(Clientes.class, Integer.parseInt(idcliente)));
                    fc.setInstalacion((Instalacion) helper.obtenerObjeto(Instalacion.class,
                            Integer.parseInt(idinstalacion)));
                    fc.setRentabilidad(f2.getjLabel20().getText());
                    fc.setValor1(f2.getjLabel11().getText().substring(2, f2.getjLabel11().getText().length()));
                    fc.setValor2(f2.getjLabel2().getText().substring(3, f2.getjLabel2().getText().length()));
                    fc.setDiferido(f2.getjLabel4().getText());
                    fc.setDias(numeroinstala);
                    helper.crearObjeto(fc);
                    helper.confirmarTransaccion();
                    helper.cerrarSesion();
                    JOptionPane.showMessageDialog(null,
                            "Comision prepara con fecha " + Funcion.DateFormatSql(d.getTime()));
                } else {
                    Calendar d = Calendar.getInstance();
                    fc.setFecha(new java.sql.Date(d.getTime().getTime()));
                    fc.setRentabilidad(f2.getjLabel20().getText());
                    fc.setValor1(f2.getjLabel11().getText().substring(2, f2.getjLabel11().getText().length()));
                    fc.setValor2(f2.getjLabel2().getText().substring(3, f2.getjLabel2().getText().length()));
                    fc.setDiferido(f2.getjLabel4().getText());
                    fc.setDias(numeroinstala);
                    helper.actualizarObjeto(fc);
                    helper.confirmarTransaccion();
                    helper.cerrarSesion();
                    JOptionPane.showMessageDialog(null,
                            "Actualizado / Comision prepara con fecha " + Funcion.DateFormatSql(d.getTime()));
                }
            } catch (Exception io) {
                System.out.println(io);
            }
        }
    });
    f2.getjButton2().addMouseListener(new java.awt.event.MouseAdapter() {
        @Override
        @SuppressWarnings("UseSpecificCatch")
        public void mouseClicked(MouseEvent e) {
            float ancho = 0;
            try {
                Document documento = new Document(PageSize.A4, 0, 0, 0, 0);
                ancho = documento.getPageSize().getWidth() - 100;
                FileOutputStream ficheroPdf;
                PdfWriter writer = null;
                PdfWriter writer2 = null;
                String direccion = "";
                Calendar now2 = Calendar.getInstance();
                try {
                    JFileChooser chooser = new JFileChooser();
                    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                    //Mostrar la ventana para abrir archivo y recoger la respuesta
                    //En el parmetro del showOpenDialog se indica la ventana
                    //  al que estar asociado. Con el valor this se asocia a la
                    //  ventana que la abre.
                    int respuesta = chooser.showOpenDialog(null);
                    String cadena = "";
                    if (respuesta == JFileChooser.APPROVE_OPTION) {
                        direccion = chooser.getSelectedFile().getAbsolutePath();
                    }
                    Calendar d = Calendar.getInstance();
                    ficheroPdf = new FileOutputStream(direccion + "/" + idcliente + idinstalacion + ".pdf");
                    writer = PdfWriter.getInstance(documento, ficheroPdf);
                } catch (IOException ex) {
                    System.out.println(ex.toString());
                }
                ServiceHb helper = null;
                try {
                    List<Productos> lt = null;
                    helper = new ServiceHb();
                    helper.iniciarTransaccion();
                    PdfPTable tabla;
                    PdfPCell casilla;
                    PdfPTable salto = null;
                    PdfPCell celda;
                    Font fontpersonalizado = FontFactory.getFont("ARIAL", 7, Font.BOLD);
                    Font fontpersonalizado2 = FontFactory.getFont("ARIAL", 7, Font.NORMAL);
                    documento.open();
                    PdfContentByte canvas = writer.getDirectContent();
                    fondos(documento, canvas);
                    //Materiales
                    double total = 0;
                    double total2 = 0;
                    double total3 = 0;
                    double total4 = 0;
                    double total5 = 0;
                    tabla = new PdfPTable(6);
                    tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
                    tabla.setTotalWidth(ancho);
                    tabla.setLockedWidth(true);
                    celda = new PdfPCell(new Paragraph("ADQUISICION DE MATERIALES"));
                    celda.setColspan(6);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    celda.setBorder(PdfPCell.NO_BORDER);
                    tabla.addCell(celda);
                    float pagina = documento.getPageSize().getHeight() - 140;
                    final float max = pagina;
                    pagina = pagina - tabla.getRow(0).calculateHeights();
                    if (ltart != null) {
                        Object nuevo2[] = { "FECHA", "DETALLE", "CANT.", "PRECIO", "SUBTOTAL", "TOTAL DIARIO" };
                        for (Object obj : nuevo2) {
                            celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado)));
                            celda.setBorderColor(new Color(195, 195, 195));
                            celda.setColspan(1);
                            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                            tabla.addCell(celda);
                        }
                        pagina = pagina - tabla.getRow(1).calculateHeights();
                        int tam = 0;
                        double diario = 0;
                        int turno = 0;
                        for (int i = 0; i < ltart.size(); i++) {
                            turno = 0;
                            fact = helper.getFacturafecha(ltart.get(i).getIdfactura());
                            String fecha = "";
                            if (fact != null) {
                                fecha = Funcion.DateFormatSql(fact.getFecha());
                            }
                            if ((i + 1) == ltart.size()) {
                                diario = diario + Double.parseDouble(ltart.get(i).getTotal());
                                turno = 1;
                            } else {
                                fact2 = helper.getFacturafecha(ltart.get(i + 1).getIdfactura());
                                String fecha2 = "";
                                if (fact2 != null) {
                                    fecha2 = Funcion.DateFormatSql(fact2.getFecha());
                                    if (fecha.equalsIgnoreCase(fecha2)) {
                                        diario = diario + Double.parseDouble(ltart.get(i).getTotal());
                                    } else {
                                        diario = diario + Double.parseDouble(ltart.get(i).getTotal());
                                        turno = 1;
                                    }
                                }
                            }
                            String uni = "$ " + df.format(Double.parseDouble(ltart.get(i).getUnitario()))
                                    .replace(",", ".");
                            String tot = "$ "
                                    + df.format(Double.parseDouble(ltart.get(i).getTotal())).replace(",", ".");
                            total = total + Double.parseDouble(ltart.get(i).getTotal());
                            if (turno == 0) {
                                Object nuevo[] = { fecha, ltart.get(i).getDescripcion(),
                                        ltart.get(i).getCantidad(), uni, tot, "" };
                                for (Object obj : nuevo) {

                                    celda = new PdfPCell(
                                            new Paragraph((String) obj, new Font(fontpersonalizado2)));
                                    if (((String) obj).equalsIgnoreCase("")) {
                                        celda.setBorder(Rectangle.RIGHT);
                                    }
                                    celda.setBorderColor(new Color(195, 195, 195));
                                    celda.setColspan(1);
                                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                                    tabla.addCell(celda);
                                }
                            } else {
                                Object nuevo[] = { fecha, ltart.get(i).getDescripcion(),
                                        ltart.get(i).getCantidad(), uni, tot,
                                        "$ " + df.format(diario).replace(",", ".") };
                                int va = 0;
                                for (Object obj : nuevo) {
                                    va++;
                                    celda = new PdfPCell(
                                            new Paragraph((String) obj, new Font(fontpersonalizado2)));
                                    if (va == 5) {
                                        celda.setBorder(Rectangle.BOTTOM);
                                    }
                                    celda.setColspan(1);
                                    celda.setBorderColor(new Color(195, 195, 195));
                                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                                    tabla.addCell(celda);
                                }
                                diario = 0;
                            }
                            pagina = pagina - tabla.getRow(tam).getMaxHeights();
                            tam++;
                            if (pagina < 11) {
                                salto = new PdfPTable(1);
                                casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado)));
                                casilla.setMinimumHeight(90);
                                casilla.setBorder(PdfPCell.NO_BORDER);
                                salto.addCell(casilla);
                                documento.add(salto);

                                documento.add(tabla);
                                documento.newPage();
                                fondos(documento, canvas);
                                tabla = new PdfPTable(6);
                                tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
                                tabla.setTotalWidth(ancho);
                                tabla.setLockedWidth(true);
                                pagina = max;
                                tam = 0;
                            }

                        }
                    }
                    salto = new PdfPTable(1);
                    casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado)));
                    casilla.setMinimumHeight(90);
                    casilla.setBorder(PdfPCell.NO_BORDER);
                    salto.addCell(casilla);
                    documento.add(salto);

                    celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(1);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    celda = new PdfPCell(
                            new Paragraph("Adquisicin de Materiales", new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(4);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    celda = new PdfPCell(new Paragraph("$ " + df.format(total).replace(",", "."),
                            new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(1);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    documento.add(tabla);
                    documento.newPage();
                    fondos(documento, canvas);
                    /*Parte 2*/

                    tabla = new PdfPTable(4);
                    tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
                    tabla.setTotalWidth(ancho);
                    tabla.setLockedWidth(true);
                    tabla.setWidths(new int[] { 1, 3, 1, 1 });
                    celda = new PdfPCell(new Paragraph("MANO DE OBRA TECNICOS"));
                    celda.setColspan(4);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    celda.setBorder(PdfPCell.NO_BORDER);
                    tabla.addCell(celda);
                    pagina = documento.getPageSize().getHeight() - 140;
                    pagina = pagina - tabla.getRow(0).calculateHeights();

                    if (list != null) {
                        Object nuevo2[] = { "FECHA", "DETALLE", "CANT.", "SUBTOTAL" };
                        for (Object obj : nuevo2) {
                            celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado)));
                            celda.setBorderColor(new Color(195, 195, 195));
                            celda.setColspan(1);
                            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                            tabla.addCell(celda);
                        }
                        pagina = pagina - tabla.getRow(1).calculateHeights();
                        int tam = 0;
                        double diario = 0;
                        int turno = 0;
                        for (Ctepagar list1 : list) {
                            if (list1.getDetalle().contains("ci:")) {
                                String fecha = list1.getFecha();
                                String desc = list1.getDetalle();
                                String[] cadena = desc.split(" ");
                                String result = "";
                                int contador = 0;
                                for (String n : cadena) {
                                    if (n.contains("ci:")) {
                                        result = result + ", ";
                                        contador++;
                                    } else {
                                        result = result + n + " ";
                                    }
                                }
                                result = result.substring(0, result.length() - 2);
                                String uni = "$ "
                                        + df.format(Double.parseDouble(list1.getValor())).replace(",", ".");
                                String tot = "$ "
                                        + df.format(Double.parseDouble(list1.getValor())).replace(",", ".");
                                total2 = total2 + Double.parseDouble(list1.getValor());
                                Object nuevo[] = { fecha, result, "" + contador, tot };
                                for (Object obj : nuevo) {
                                    celda = new PdfPCell(
                                            new Paragraph((String) obj, new Font(fontpersonalizado2)));
                                    celda.setBorderColor(new Color(195, 195, 195));
                                    celda.setColspan(1);
                                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                                    tabla.addCell(celda);
                                }
                                pagina = pagina - tabla.getRow(tam).getMaxHeights();
                                tam++;
                                if (pagina < 90) {
                                    salto = new PdfPTable(1);
                                    casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado2)));
                                    casilla.setMinimumHeight(90);
                                    casilla.setBorder(PdfPCell.NO_BORDER);
                                    salto.addCell(casilla);
                                    documento.add(salto);

                                    documento.add(tabla);
                                    documento.newPage();
                                    fondos(documento, canvas);
                                    tabla = new PdfPTable(4);
                                    tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
                                    tabla.setTotalWidth(ancho);
                                    tabla.setLockedWidth(true);
                                    tabla.setWidths(new int[] { 1, 3, 1, 1 });
                                    pagina = max;
                                    tam = 0;
                                }
                            }
                        }
                    }
                    salto = new PdfPTable(1);
                    casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado)));
                    casilla.setMinimumHeight(90);
                    casilla.setBorder(PdfPCell.NO_BORDER);
                    salto.addCell(casilla);
                    documento.add(salto);

                    celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(1);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    celda = new PdfPCell(new Paragraph("Mano de Obra Tcnicos", new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(2);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    celda = new PdfPCell(new Paragraph("$ " + df.format(total2).replace(",", "."),
                            new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(1);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    documento.add(tabla);

                    documento.newPage();
                    fondos(documento, canvas);

                    tabla = new PdfPTable(3);
                    tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
                    tabla.setTotalWidth(ancho);
                    tabla.setLockedWidth(true);
                    tabla.setWidths(new int[] { 1, 3, 1 });
                    celda = new PdfPCell(new Paragraph("TRANSPORTE"));
                    celda.setColspan(3);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    celda.setBorder(PdfPCell.NO_BORDER);
                    tabla.addCell(celda);
                    pagina = documento.getPageSize().getHeight() - 140;
                    pagina = pagina - tabla.getRow(0).calculateHeights();

                    if (list != null) {
                        Object nuevo2[] = { "FECHA", "DETALLE", "SUBTOTAL" };
                        for (Object obj : nuevo2) {
                            celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado)));
                            celda.setBorderColor(new Color(195, 195, 195));
                            celda.setColspan(1);
                            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                            tabla.addCell(celda);
                        }
                        pagina = pagina - tabla.getRow(1).calculateHeights();
                        int tam = 0;
                        for (Ctepagar list1 : list) {
                            if (list1.getDetalle().contains("Transporte")) {
                                String fecha = list1.getFecha();
                                String desc = list1.getDetalle();
                                String result = "";
                                String uni = "$ "
                                        + df.format(Double.parseDouble(list1.getValor())).replace(",", ".");
                                String tot = "$ "
                                        + df.format(Double.parseDouble(list1.getValor())).replace(",", ".");
                                total3 = total3 + Double.parseDouble(list1.getValor());
                                Object nuevo[] = { fecha, desc, tot };
                                for (Object obj : nuevo) {
                                    celda = new PdfPCell(
                                            new Paragraph((String) obj, new Font(fontpersonalizado2)));
                                    celda.setBorderColor(new Color(195, 195, 195));
                                    celda.setColspan(1);
                                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                                    tabla.addCell(celda);
                                }
                                pagina = pagina - tabla.getRow(tam).getMaxHeights();
                                tam++;
                                if (pagina < 50) {
                                    salto = new PdfPTable(1);
                                    casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado2)));
                                    casilla.setMinimumHeight(90);
                                    casilla.setBorder(PdfPCell.NO_BORDER);
                                    salto.addCell(casilla);
                                    documento.add(salto);

                                    documento.add(tabla);
                                    documento.newPage();
                                    fondos(documento, canvas);
                                    tabla = new PdfPTable(3);
                                    tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
                                    tabla.setTotalWidth(ancho);
                                    tabla.setLockedWidth(true);
                                    tabla.setWidths(new int[] { 1, 3, 1 });
                                    pagina = max;
                                    tam = 0;
                                }
                            }
                        }
                    }
                    salto = new PdfPTable(1);
                    casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado)));
                    casilla.setMinimumHeight(90);
                    casilla.setBorder(PdfPCell.NO_BORDER);
                    salto.addCell(casilla);
                    documento.add(salto);

                    celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(1);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    celda = new PdfPCell(new Paragraph("Transporte", new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(1);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    celda = new PdfPCell(new Paragraph("$ " + df.format(total3).replace(",", "."),
                            new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(1);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    documento.add(tabla);

                    documento.newPage();
                    fondos(documento, canvas);

                    tabla = new PdfPTable(3);
                    tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
                    tabla.setTotalWidth(ancho);
                    tabla.setLockedWidth(true);
                    tabla.setWidths(new int[] { 1, 3, 1 });
                    celda = new PdfPCell(new Paragraph("COMBUSTIBLE"));
                    celda.setColspan(3);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    celda.setBorder(PdfPCell.NO_BORDER);
                    tabla.addCell(celda);
                    pagina = documento.getPageSize().getHeight() - 140;
                    pagina = pagina - tabla.getRow(0).calculateHeights();

                    if (list != null) {
                        Object nuevo2[] = { "FECHA", "DETALLE", "SUBTOTAL" };
                        for (Object obj : nuevo2) {
                            celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado)));
                            celda.setBorderColor(new Color(195, 195, 195));
                            celda.setColspan(1);
                            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                            tabla.addCell(celda);
                        }
                        pagina = pagina - tabla.getRow(1).calculateHeights();
                        int tam = 0;
                        for (Ctepagar list1 : list) {
                            if (list1.getDetalle().contains("Combustible")) {
                                String fecha = list1.getFecha();
                                String desc = list1.getDetalle();
                                String result = "";
                                String uni = "$ "
                                        + df.format(Double.parseDouble(list1.getValor())).replace(",", ".");
                                String tot = "$ "
                                        + df.format(Double.parseDouble(list1.getValor())).replace(",", ".");
                                total4 = total4 + Double.parseDouble(list1.getValor());
                                Object nuevo[] = { fecha, desc, tot };
                                for (Object obj : nuevo) {
                                    celda = new PdfPCell(
                                            new Paragraph((String) obj, new Font(fontpersonalizado2)));
                                    celda.setBorderColor(new Color(195, 195, 195));
                                    celda.setColspan(1);
                                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                                    tabla.addCell(celda);
                                }
                                pagina = pagina - tabla.getRow(tam).getMaxHeights();
                                tam++;
                                if (pagina < 50) {
                                    salto = new PdfPTable(1);
                                    casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado)));
                                    casilla.setMinimumHeight(90);
                                    casilla.setBorder(PdfPCell.NO_BORDER);
                                    salto.addCell(casilla);
                                    documento.add(salto);

                                    documento.add(tabla);
                                    documento.newPage();
                                    fondos(documento, canvas);
                                    tabla = new PdfPTable(3);
                                    tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
                                    tabla.setTotalWidth(ancho);
                                    tabla.setLockedWidth(true);
                                    tabla.setWidths(new int[] { 1, 3, 1 });
                                    pagina = max;
                                    tam = 0;
                                }
                            }
                        }
                    }
                    salto = new PdfPTable(1);
                    casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado)));
                    casilla.setMinimumHeight(90);
                    casilla.setBorder(PdfPCell.NO_BORDER);
                    salto.addCell(casilla);
                    documento.add(salto);

                    celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(1);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    celda = new PdfPCell(new Paragraph("Combustible", new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(1);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    celda = new PdfPCell(new Paragraph("$ " + df.format(total4).replace(",", "."),
                            new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(1);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    documento.add(tabla);

                    documento.newPage();
                    fondos(documento, canvas);

                    //Extras

                    tabla = new PdfPTable(3);
                    tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
                    tabla.setTotalWidth(ancho);
                    tabla.setLockedWidth(true);
                    tabla.setWidths(new int[] { 1, 3, 1 });
                    celda = new PdfPCell(new Paragraph("EXTRAS"));
                    celda.setColspan(3);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    celda.setBorder(PdfPCell.NO_BORDER);
                    tabla.addCell(celda);
                    pagina = documento.getPageSize().getHeight() - 140;
                    pagina = pagina - tabla.getRow(0).calculateHeights();

                    if (list != null) {
                        Object nuevo2[] = { "FECHA", "DETALLE", "SUBTOTAL" };
                        for (Object obj : nuevo2) {
                            celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado)));
                            celda.setBorderColor(new Color(195, 195, 195));
                            celda.setColspan(1);
                            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                            tabla.addCell(celda);
                        }
                        pagina = pagina - tabla.getRow(1).calculateHeights();
                        int tam = 0;
                        for (Ctepagar list1 : list) {
                            if (!list1.getDetalle().contains("Combustible")
                                    && !list1.getDetalle().contains("ci:")
                                    && !list1.getDetalle().contains("Transporte")) {
                                String fecha = list1.getFecha();
                                String desc = list1.getDetalle();
                                String result = "";
                                String uni = "$ "
                                        + df.format(Double.parseDouble(list1.getValor())).replace(",", ".");
                                String tot = "$ "
                                        + df.format(Double.parseDouble(list1.getValor())).replace(",", ".");
                                total5 = total5 + Double.parseDouble(list1.getValor());
                                Object nuevo[] = { fecha, desc, tot };
                                for (Object obj : nuevo) {
                                    celda = new PdfPCell(
                                            new Paragraph((String) obj, new Font(fontpersonalizado2)));
                                    celda.setBorderColor(new Color(195, 195, 195));
                                    celda.setColspan(1);
                                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                                    tabla.addCell(celda);
                                }
                                pagina = pagina - tabla.getRow(tam).getMaxHeights();
                                tam++;
                                if (pagina < 50) {
                                    salto = new PdfPTable(1);
                                    casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado)));
                                    casilla.setMinimumHeight(90);
                                    casilla.setBorder(PdfPCell.NO_BORDER);
                                    salto.addCell(casilla);
                                    documento.add(salto);

                                    documento.add(tabla);
                                    documento.newPage();
                                    fondos(documento, canvas);
                                    tabla = new PdfPTable(3);
                                    tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
                                    tabla.setTotalWidth(ancho);
                                    tabla.setLockedWidth(true);
                                    tabla.setWidths(new int[] { 1, 3, 1 });
                                    pagina = max;
                                    tam = 0;
                                }
                            }
                        }
                    }
                    salto = new PdfPTable(1);
                    casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado)));
                    casilla.setMinimumHeight(90);
                    casilla.setBorder(PdfPCell.NO_BORDER);
                    salto.addCell(casilla);
                    documento.add(salto);

                    celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(1);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    celda = new PdfPCell(new Paragraph("Extra", new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(1);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    celda = new PdfPCell(new Paragraph("$ " + df.format(total5).replace(",", "."),
                            new Font(fontpersonalizado2)));
                    celda.setBorderColor(new Color(195, 195, 195));
                    celda.setColspan(1);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                    documento.add(tabla);

                    documento.newPage();
                    fondos(documento, canvas);

                    //Final Vendedor

                    tabla = new PdfPTable(3);
                    tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
                    tabla.setTotalWidth(ancho);
                    tabla.setLockedWidth(true);
                    tabla.setWidths(new int[] { 1, 3, 1 });
                    celda = new PdfPCell(new Paragraph(nombrecliente));
                    celda.setColspan(3);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    celda.setBorder(PdfPCell.NO_BORDER);
                    tabla.addCell(celda);

                    celda = new PdfPCell(new Paragraph("Venta"));
                    celda.setColspan(3);
                    celda.setHorizontalAlignment(Element.ALIGN_LEFT);
                    celda.setBorder(PdfPCell.NO_BORDER);
                    tabla.addCell(celda);

                    pagina = documento.getPageSize().getHeight() - 140;
                    pagina = pagina - tabla.getRow(0).calculateHeights();

                    Object nuevo2[] = { "FECHA", "DETALLE", "TOTAL" };
                    for (Object obj : nuevo2) {
                        celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado)));
                        celda.setBorderColor(new Color(195, 195, 195));
                        celda.setColspan(1);
                        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tabla.addCell(celda);
                    }
                    Object nuevo3[] = { "", nombreinstalacion, totalinstalacion };
                    for (Object obj : nuevo3) {
                        celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2)));
                        celda.setBorderColor(new Color(195, 195, 195));
                        celda.setColspan(1);
                        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tabla.addCell(celda);
                    }
                    celda = new PdfPCell(new Paragraph("INVERSION", new Font(fontpersonalizado)));
                    celda.setBorder(PdfPCell.NO_BORDER);
                    celda.setColspan(3);
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);
                    Object nuevo4[] = { "Uso de Materiales", "", "$ " + df.format(total).replace(",", ".") };
                    for (Object obj : nuevo4) {
                        celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2)));
                        celda.setBorder(PdfPCell.NO_BORDER);
                        celda.setColspan(1);
                        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tabla.addCell(celda);
                    }
                    Object nuevo5[] = { "Mano de obra tcnicos", "",
                            "$ " + df.format(total2).replace(",", ".") };
                    for (Object obj : nuevo5) {
                        celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2)));
                        celda.setBorder(PdfPCell.NO_BORDER);
                        celda.setColspan(1);
                        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tabla.addCell(celda);
                    }
                    Object nuevo6[] = { "Transporte", "", "$ " + df.format(total3).replace(",", ".") };
                    for (Object obj : nuevo6) {
                        celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2)));
                        celda.setBorder(PdfPCell.NO_BORDER);
                        celda.setColspan(1);
                        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tabla.addCell(celda);
                    }
                    Object nuevo7[] = { "Combustible", "", "$ " + df.format(total4).replace(",", ".") };
                    for (Object obj : nuevo7) {
                        celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2)));
                        celda.setBorder(PdfPCell.NO_BORDER);
                        celda.setColspan(1);
                        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tabla.addCell(celda);
                    }
                    Object nuevo71[] = { "Extras", "", "$ " + df.format(total5).replace(",", ".") };
                    for (Object obj : nuevo71) {
                        celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2)));
                        celda.setBorder(PdfPCell.NO_BORDER);
                        celda.setColspan(1);
                        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tabla.addCell(celda);
                    }
                    Object nuevo8[] = { "Total Inversin", "",
                            "$ " + df.format(total + total2 + total3 + total4).replace(",", ".") };
                    for (Object obj : nuevo8) {
                        celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2)));
                        celda.setBorder(PdfPCell.NO_BORDER);
                        celda.setColspan(1);
                        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tabla.addCell(celda);
                    }
                    celda = new PdfPCell(new Paragraph(""));
                    celda.setColspan(3);
                    celda.setHorizontalAlignment(Element.ALIGN_LEFT);
                    celda.setBorder(PdfPCell.NO_BORDER);
                    tabla.addCell(celda);

                    Object nuevo9[] = { "Utilidad del proyecto", "", "$ "
                            + df.format(proyectoval - total - total2 - total3 - total4).replace(",", ".") };
                    for (Object obj : nuevo9) {
                        celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado)));
                        celda.setColspan(1);
                        celda.setBorder(PdfPCell.NO_BORDER);
                        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tabla.addCell(celda);
                    }
                    Object nuevo10[] = { "Rentabilidad ", "", df.format(porcent).replace(",", ".") + " %" };
                    for (Object obj : nuevo10) {
                        celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado)));
                        celda.setBorder(PdfPCell.NO_BORDER);
                        celda.setColspan(1);
                        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tabla.addCell(celda);
                    }

                    salto = new PdfPTable(1);
                    casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado)));
                    casilla.setMinimumHeight(90);
                    casilla.setBorder(PdfPCell.NO_BORDER);
                    salto.addCell(casilla);
                    documento.add(salto);

                    documento.add(tabla);

                    /*Fin Parte 3*/
                    documento.close();
                    helper.cerrarSesion();
                } catch (Exception ex) {
                    documento.close();
                }
                JOptionPane.showMessageDialog(null, "PDF Generado");
            } catch (Exception io) {
                System.out.println(io);
            }
        }
    });
    f.getjTable1().addMouseListener(new java.awt.event.MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            int row = f.getjTable1().getSelectedRow();
            int col = f.getjTable1().getSelectedColumn();
            if (col == 4) {
                f2.setVisible(true);
                f.setVisible(false);
                idcliente = f.getjTable1().getValueAt(row, 5).toString();
                idinstalacion = f.getjTable1().getValueAt(row, 6).toString();
                f2.getjLabel15().setText(f.getjTable1().getValueAt(row, 0).toString());
                f2.getjLabel8().setText(f.getjTable1().getValueAt(row, 2).toString());
                nombrecliente = f.getjTable1().getValueAt(row, 0).toString();
                nombreinstalacion = f.getjTable1().getValueAt(row, 2).toString();
                updateTablas up = new updateTablas(1);
                up.start();
            }
        }
    });
    f5.getjComboBox1().addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            DefaultTableModel temp2 = (DefaultTableModel) f5.getjTable2().getModel();
            for (int i = temp2.getRowCount() - 1; i >= 0; i--) {
                temp2.removeRow(i);
            }
            f5.setComi(null);
            f5.setNinstalacion("");
            f5.setNcliente("");
            f5.setList(null);
            f5.setId("");
            updateTablas up = new updateTablas(4);
            up.start();
        }
    });
    f3.getjTable1().addMouseListener(new java.awt.event.MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            int row = f3.getjTable1().getSelectedRow();
            int col = f3.getjTable1().getSelectedColumn();
            if (col == 6) {
                visible(f4);
                fcomisiones = f3.getjTable1().getValueAt(row, 6).toString();
                try {
                    ServiceHb helper = new ServiceHb();
                    helper.iniciarTransaccion();
                    Fcomisiones ft = (Fcomisiones) helper.obtenerObjeto(Fcomisiones.class,
                            Integer.parseInt(fcomisiones));
                    numeroinstala = ft.getDias();
                    f4.setIdcliente("" + ft.getClientes().getId());
                    f4.setIdinstalacion("" + ft.getInstalacion().getId());
                    f4.getDiasint().setText(numeroinstala);
                    helper.cerrarSesion();
                } catch (Exception io) {

                }
                f4.getjLabel1().setText(fcomisiones);
                f4.getC1().setText(f3.getjTable1().getValueAt(row, 0).toString());
                f4.getC2().setText(f3.getjTable1().getValueAt(row, 1).toString());
                double campo1 = Double
                        .parseDouble(f3.getjTable1().getValueAt(row, 3).toString().replace("$ ", ""));
                double campo2 = Double
                        .parseDouble(f3.getjTable1().getValueAt(row, 4).toString().replace("-$ ", ""));
                f4.getC3().setText(f3.getjTable1().getValueAt(row, 3).toString());
                f4.getC4().setText(f3.getjTable1().getValueAt(row, 4).toString());
                f4.getC5().setText(f3.getjTable1().getValueAt(row, 5).toString());
                f4.getC6().setText("$ " + df.format((campo1 - campo2)).replace(",", "."));

                updateTablas up = new updateTablas(3);
                up.start();
            }
        }
    });

    setVisible(false);
}