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

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

Introduction

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

Prototype

public PdfPCell getDefaultCell() 

Source Link

Document

Gets the default PdfPCell that will be used as reference for all the addCell methods except addCell(PdfPCell).

Usage

From source file:Main_Frame.java

private void jMenuItem29ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem29ActionPerformed
    try {/*w  w w.  j a v  a 2  s  .co  m*/
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con1 = DriverManager.getConnection("jdbc:odbc:College");
        Statement stm1 = con1.createStatement();
        //Statement stm1 = con1.createStatement();
        ResultSet rs = stm1.executeQuery("SELECT * from Slot_Details");
        //ResultSet rs1 = stm2.executeQuery("SELECT * from Slot_Details");
        String[] start = new String[10];
        String[] end = new String[10];
        int line = 0;
        while (rs.next()) {

            start[line] = rs.getString("START");
            end[line] = rs.getString("END");
            line++;
        }

        /*   try{
        Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); 
        Connection con2=DriverManager.getConnection("jdbc:odbc:College");*/
        Statement stm2 = con1.createStatement();
        ResultSet query_set = stm2.executeQuery("SELECT * from format");
        /* Step-2: Initialize PDF documents - logical objects */
        Document my_pdf_report = new Document(PageSize.A4);
        PdfWriter.getInstance(my_pdf_report, new FileOutputStream("C:\\Users\\Durga\\Desktop\\Time_Table.pdf"));
        my_pdf_report.open();
        //we have four columns in our table

        PdfPTable table = new PdfPTable(10);
        //table.setWidthPercentage(100);
        //          table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

        String a[] = { "//////", "//////", "//////", "//////", "//////", "//////", "//////", "//////", "L", "U",
                "N", "C", "H", "//////", "//////", "//////", "//////", "//////", "//////" };

        int len = 1;
        table.addCell("Day");

        table.addCell("Branch");

        String s;

        for (int i = 0; i < line; i++) {
            int j = i;
            if (i == 5)
                table.addCell(a[0]);
            if (i >= 5)
                j = line - 1;
            table.addCell("Period" + (i) + " \n[" + start[j] + "-" + end[j] + "]");

        }

        table.getDefaultCell().setFixedHeight(70);
        table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
        while (query_set.next()) {
            String Day = query_set.getString("Day");
            table.addCell(Day);

            String Branch = query_set.getString("Branch");
            table.addCell(Branch);

            for (int i = 0; i < line; i++) {
                if (i == 5) {
                    table.addCell(a[len++]);

                    table.addCell(query_set.getString("slot" + (i + 1)) + "G1");
                } else if (i == 6) {
                    table.addCell(query_set.getString("slot" + (i + 1)) + "G2");
                } else
                    table.addCell(query_set.getString("slot" + (i + 1)));

            }
        }

        /* Attach report table to PDF */
        // my_pdf_report.add(my_report_table);  
        my_pdf_report.add(table);
        my_pdf_report.close();

        /* Close all DB related objects */
        query_set.close();
        stm2.close();
        //con2.close();     
        // }
        /*  catch(Exception e)
           {
           System.out.println(e);
            }*/
        stm1.close();
        con1.close();
    } catch (Exception e) {
        System.out.println(e);
    }

    if (Desktop.isDesktopSupported()) //Open pdf file
    {
        try {
            File myFile = new File("C:\\Users\\Durga\\Desktop\\Time_Table.pdf");
            Desktop.getDesktop().open(myFile);
        } catch (Exception ex) {
            System.out.println(ex);
        }
        //System.out.println(ex);
    }
}

From source file:AppPackage.printPDF.java

public void printNow(String id, String name, String dateRange, String underLate, String workedHours,
        String totalHours, String dateNow, String fDate, String lDate, String type, String empTypeRate,
        int lastRId, double salary) {
    this.id = id;
    this.name = name;
    this.dateRange = dateRange;
    this.underLate = underLate;
    this.workedHours = workedHours;
    this.totalHours = totalHours;
    this.dateNow = dateNow;
    this.fDate = fDate;
    this.lDate = lDate;
    this.type = type;
    this.empTypeRate = empTypeRate;
    this.lastRId = lastRId;
    this.salary = salary;
    try {//from ww w. j  a v  a 2  s  .c o  m

        Document document = new Document();
        Connection conn = null;
        Statement st = null;
        conn = dbC.getConnection();
        st = conn.createStatement();

        String query = "SELECT * FROM schedule WHERE empId ='" + id + "'";
        ResultSet rs = st.executeQuery(query);

        PdfWriter.getInstance(document,
                new FileOutputStream("reports/Report-" + reportCount + "." + lastRId + "-" + id + ".pdf"));
        document.open();
        document.setPageSize(PageSize.LETTER);
        document.setMargins(0f, 0f, 0f, 0f);

        Image image = Image.getInstance("Resources/DTRHeaderTwo.png");
        document.add(image);

        PdfPTable ICTable = new PdfPTable(5);
        ICTable.setWidthPercentage(100);

        ICTable.getDefaultCell().setBorder(0);
        //create a cell object
        PdfPCell ICTableCell;

        Phrase ICBlank = new Phrase();
        Phrase ICharge = new Phrase();
        Phrase ICBlanko = new Phrase();
        Phrase ICBlankx = new Phrase();
        Phrase IChargex = new Phrase();

        ICBlank.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC)));
        ICTable.addCell(ICBlank);
        ICharge.add(new Chunk("_____________________", new Font(Font.FontFamily.HELVETICA, 8, Font.ITALIC)));
        ICTable.addCell(ICharge);
        ICBlanko.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC)));
        ICTable.addCell(ICBlanko);
        ICBlankx.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC)));
        ICTable.addCell(ICBlankx);
        IChargex.add(new Chunk("____________________", new Font(Font.FontFamily.HELVETICA, 8, Font.ITALIC)));
        ICTable.addCell(IChargex);

        ICTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        ICTableCell.setBorder(PdfPCell.NO_BORDER);
        ICTable.addCell(ICTableCell);
        ICTableCell = new PdfPCell(
                new Phrase("In - Charge", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        ICTableCell.setBorder(PdfPCell.NO_BORDER);
        ICTable.addCell(ICTableCell);
        ICTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        ICTableCell.setBorder(PdfPCell.NO_BORDER);
        ICTable.addCell(ICTableCell);

        ICTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        ICTableCell.setBorder(PdfPCell.NO_BORDER);
        ICTable.addCell(ICTableCell);
        ICTableCell = new PdfPCell(
                new Phrase("In - Charge", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        ICTableCell.setBorder(PdfPCell.NO_BORDER);
        ICTable.addCell(ICTableCell);

        PdfPTable dateRecTable = new PdfPTable(5);
        dateRecTable.setWidthPercentage(100);

        dateRecTable.getDefaultCell().setBorder(0);
        //create a cell object
        PdfPCell dateRecTableCell;

        Phrase dRDate = new Phrase();
        Phrase dRNo = new Phrase();
        Phrase dRBlank = new Phrase();
        Phrase dRDatex = new Phrase();
        Phrase dRNox = new Phrase();

        dRDate.add(
                new Chunk("Released #: " + lastRId + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC)));
        dateRecTable.addCell(dRDate);
        dRNo.add(new Chunk("" + dateNow + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC)));
        dateRecTable.addCell(dRNo);
        dRBlank.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC)));
        dateRecTable.addCell(dRBlank);
        dRDatex.add(
                new Chunk("Released #: " + lastRId + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC)));
        dateRecTable.addCell(dRDatex);
        dRNox.add(new Chunk("" + dateNow + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC)));
        dateRecTable.addCell(dRNox);

        PdfPTable InfoTable = new PdfPTable(5);
        InfoTable.setWidthPercentage(100);

        InfoTable.getDefaultCell().setBorder(0);
        //create a cell object
        PdfPCell InfoTableCell;

        Phrase infoId = new Phrase();
        Phrase infoType = new Phrase();
        Phrase infoBlank = new Phrase();
        Phrase infoIdx = new Phrase();
        Phrase infoTypex = new Phrase();

        infoId.add(new Chunk("ID: " + id + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTable.addCell(infoId);
        infoType.add(new Chunk("Type: " + type + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTable.addCell(infoType);
        infoBlank.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTable.addCell(infoBlank);
        infoIdx.add(new Chunk("ID: " + id + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTable.addCell(infoIdx);
        infoTypex.add(new Chunk("Type: " + type + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTable.addCell(infoTypex);

        InfoTableCell = new PdfPCell(
                new Phrase("Fullname: " + name + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);
        InfoTableCell = new PdfPCell(new Phrase("Hourly Rate: " + empTypeRate + "",
                new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);
        InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);

        InfoTableCell = new PdfPCell(
                new Phrase("Fullname: " + name + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);
        InfoTableCell = new PdfPCell(new Phrase("Hourly Rate: " + empTypeRate + "",
                new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);

        InfoTableCell = new PdfPCell(new Phrase("Date Range: \n" + dateRange + "",
                new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);
        InfoTableCell = new PdfPCell(new Phrase("Total Hours: " + totalHours + "",
                new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);
        InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);

        InfoTableCell = new PdfPCell(new Phrase("Date Range: \n" + dateRange + "",
                new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);
        InfoTableCell = new PdfPCell(new Phrase("Total Hours: " + totalHours + "",
                new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);

        InfoTableCell = new PdfPCell(new Phrase("Late & Under Time: " + underLate + "",
                new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);
        InfoTableCell = new PdfPCell(new Phrase("Worked Hours: " + workedHours + "",
                new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);
        InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);

        InfoTableCell = new PdfPCell(new Phrase("Late & Under Time: " + underLate + "",
                new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);
        InfoTableCell = new PdfPCell(new Phrase("Worked Hours: " + workedHours + "",
                new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);

        InfoTableCell = new PdfPCell(
                new Phrase("Salary: " + salary + " PHP", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);
        InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);
        InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);

        InfoTableCell = new PdfPCell(
                new Phrase("Salary: " + salary + " PHP", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);
        InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
        InfoTableCell.setBorder(PdfPCell.NO_BORDER);
        InfoTable.addCell(InfoTableCell);

        PdfPTable SchedTable = new PdfPTable(17);
        SchedTable.setWidthPercentage(100);

        SchedTable.getDefaultCell().setBorder(0);
        //create a cell object
        PdfPCell SchedTableCell;

        Phrase phraseDayS = new Phrase();
        Phrase phraseAMTotal = new Phrase();
        Phrase phraseAMStart = new Phrase();
        Phrase phraseAMEnd = new Phrase();
        Phrase phrasePMTotal = new Phrase();
        Phrase phrasePMStart = new Phrase();
        Phrase phrasePMEnd = new Phrase();
        Phrase phraseTotalTime = new Phrase();
        Phrase phraseBlankS = new Phrase();
        Phrase phraseDaySx = new Phrase();
        Phrase phraseAMTotalx = new Phrase();
        Phrase phraseAMStartx = new Phrase();
        Phrase phraseAMEndx = new Phrase();
        Phrase phrasePMTotalx = new Phrase();
        Phrase phrasePMStartx = new Phrase();
        Phrase phrasePMEndx = new Phrase();
        Phrase phraseTotalTimex = new Phrase();

        phraseDayS.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phraseDayS);
        phraseAMStart.add(new Chunk("AM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phraseAMStart);
        phraseAMEnd.add(new Chunk("AM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phraseAMEnd);
        phraseAMTotal.add(new Chunk("AM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phraseAMTotal);
        phrasePMStart.add(new Chunk("PM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phrasePMStart);
        phrasePMEnd.add(new Chunk("PM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phrasePMEnd);
        phrasePMTotal.add(new Chunk("PM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phrasePMTotal);
        phraseTotalTime.add(new Chunk("Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phraseTotalTime);
        phraseBlankS.add(new Chunk("           ", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phraseBlankS);

        phraseDaySx.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phraseDaySx);
        phraseAMStartx.add(new Chunk("AM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phraseAMStartx);
        phraseAMEndx.add(new Chunk("AM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phraseAMEndx);
        phraseAMTotalx.add(new Chunk("AM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phraseAMTotalx);
        phrasePMStartx.add(new Chunk("PM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phrasePMStartx);
        phrasePMEndx.add(new Chunk("PM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phrasePMEndx);
        phrasePMTotalx.add(new Chunk("PM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phrasePMTotalx);
        phraseTotalTimex.add(new Chunk("Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        SchedTable.addCell(phraseTotalTimex);

        while (rs.next()) {
            SimpleDateFormat readingFormat = new SimpleDateFormat("HH:mm:ss");
            SimpleDateFormat outputFormat = new SimpleDateFormat("hh:mm a");
            String dayxxx = rs.getString("day");
            String amStartxx = rs.getString("amStart");
            String amEndxx = rs.getString("amEnd");
            String pmStartxx = rs.getString("pmStart");
            String pmEndxx = rs.getString("pmEnd");
            String amTotalxx = rs.getString("amTotal");
            String pmTotalxx = rs.getString("pmTotal");
            String totalHoursxx = rs.getString("totalTime");
            String blank = "          ";

            String amStart = null;
            String amEnd = null;
            String amTotal = null;
            String pmStart = null;
            String pmEnd = null;
            String pmTotal = null;
            String totalHoursx = null;

            Date dayx = new SimpleDateFormat("EEEE").parse(dayxxx);
            SimpleDateFormat sdfxxx = new SimpleDateFormat("EEE");
            String day = sdfxxx.format(dayx);
            System.out.println(day + " day");

            try {
                Date amStartTxx = readingFormat.parse(amStartxx);
                amStart = outputFormat.format(amStartTxx);
                if (amStart.equals("12:00 AM")) {
                    amStart = "00:00";
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                Date amEndTx = readingFormat.parse(amEndxx);
                amEnd = outputFormat.format(amEndTx);
                if (amEnd.equals("12:00 AM")) {
                    amEnd = "00:00";
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                Date amTotalTx = readingFormat.parse(amTotalxx);
                amTotal = outputFormat.format(amTotalTx);
                if (amTotal.equals("12:00 AM")) {
                    amTotal = "00:00";
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                Date pmStartTxx = readingFormat.parse(pmStartxx);
                pmStart = outputFormat.format(pmStartTxx);
                if (pmStart.equals("12:00 AM")) {
                    pmStart = "00:00";
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                Date pmEndTxx = readingFormat.parse(pmEndxx);
                pmEnd = outputFormat.format(pmEndTxx);
                if (pmEnd.equals("12:00 AM")) {
                    pmEnd = "00:00";
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                Date pmTotalTxx = readingFormat.parse(pmTotalxx);
                pmTotal = outputFormat.format(pmTotalTxx);
                if (pmTotal.equals("12:00 AM")) {
                    pmTotal = "00:00";
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                Date totalHoursxT = readingFormat.parse(totalHoursxx);
                totalHoursx = outputFormat.format(totalHoursxT);
                if (totalHoursx.equals("12:00 AM")) {
                    totalHoursx = "00:00";
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(day);
            System.out.println(amStart);
            System.out.println(amEnd);
            System.out.println(amTotal);
            System.out.println(pmStart);
            System.out.println(pmEnd);
            System.out.println(pmTotal);
            System.out.println(totalHoursx);

            SchedTableCell = new PdfPCell(new Phrase(day, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(amStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(amEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(amTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(pmStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(pmEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(pmTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(totalHoursx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(new Phrase(blank));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(new Phrase(day, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(amStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(amEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(amTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(pmStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(pmEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(pmTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

            SchedTableCell = new PdfPCell(
                    new Phrase(totalHoursx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
            SchedTableCell.setBorder(PdfPCell.NO_BORDER);
            SchedTable.addCell(SchedTableCell);

        }

        PdfPTable DTRTable = new PdfPTable(17);
        DTRTable.setWidthPercentage(100);

        DTRTable.getDefaultCell().setBorder(0);
        //create a cell object
        PdfPCell DTRTableCell;

        Phrase phraseDay = new Phrase();
        Phrase phraseDate = new Phrase();
        Phrase phraseAMIn = new Phrase();
        Phrase phraseAMOut = new Phrase();
        Phrase phrasePMIn = new Phrase();
        Phrase phrasePMOut = new Phrase();
        Phrase phraseHours = new Phrase();
        Phrase phraseUTL = new Phrase();
        Phrase phraseBlank = new Phrase();
        Phrase phraseDayx = new Phrase();
        Phrase phraseDatex = new Phrase();
        Phrase phraseAMInx = new Phrase();
        Phrase phraseAMOutx = new Phrase();
        Phrase phrasePMInx = new Phrase();
        Phrase phrasePMOutx = new Phrase();
        Phrase phraseHoursx = new Phrase();
        Phrase phraseUTLx = new Phrase();

        phraseDay.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phraseDay);
        phraseDate.add(new Chunk("Date", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phraseDate);
        phraseAMIn.add(new Chunk("AM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phraseAMIn);
        phraseAMOut.add(new Chunk("AM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phraseAMOut);
        phrasePMIn.add(new Chunk("PM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phrasePMIn);
        phrasePMOut.add(new Chunk("PM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phrasePMOut);
        phraseHours.add(new Chunk("Hours", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phraseHours);
        phraseUTL.add(new Chunk("Late/U.T", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phraseUTL);
        phraseBlank.add(new Chunk("           ", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phraseBlank);

        phraseDayx.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phraseDayx);
        phraseDatex.add(new Chunk("Date", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phraseDatex);
        phraseAMInx.add(new Chunk("AM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phraseAMInx);
        phraseAMOutx.add(new Chunk("AM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phraseAMOutx);
        phrasePMInx.add(new Chunk("PM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phrasePMInx);
        phrasePMOutx.add(new Chunk("PM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phrasePMOutx);
        phraseHoursx.add(new Chunk("Hours", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phraseHoursx);
        phraseUTLx.add(new Chunk("Late/U.T", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD)));
        DTRTable.addCell(phraseUTLx);

        try {
            Connection connx = null;
            Statement stx = null;
            connx = dbC.getConnection();
            stx = connx.createStatement();

            String queryx = "SELECT timeinout.day, timeinout.date, schedule.totalTime, schedule.amTotal, "
                    + "schedule.amStart, timeinout.amTimeIn, schedule.amEnd, timeinout.amTimeOut, "
                    + "schedule.pmTotal, schedule.pmStart, timeinout.pmTimeIn, schedule.pmEnd, "
                    + "timeinout.pmTimeOut FROM timeinout LEFT JOIN "
                    + "(schedule) ON (schedule.empId = timeinout.empId AND timeinout.day = schedule.day) WHERE  "
                    + "timeinout.empId ='" + id + "' AND  schedule.empId = '" + id + "' AND date(`Date`) >= '"
                    + fDate + "' " + "AND date(`Date`) <= '" + lDate + "'";
            ResultSet rsx = stx.executeQuery(queryx);
            while (rsx.next()) {
                String day = rsx.getString("timeinout.day");
                String date = rsx.getString("timeinout.date");
                String amStartDB = rsx.getString("schedule.amStart");
                String amIn = rsx.getString("timeinout.amTimeIn");
                String amEndDB = rsx.getString("schedule.amEnd");
                String amOut = rsx.getString("timeinout.amTimeOut");
                String pmStartDB = rsx.getString("schedule.pmStart");
                String pmIn = rsx.getString("timeinout.pmTimeIn");
                String pmEndDB = rsx.getString("schedule.pmEnd");
                String pmOut = rsx.getString("timeinout.pmTimeOut");
                String totTime = rsx.getString("schedule.totalTime");
                String wHours;
                String blank = "           ";
                String dayx = rsx.getString("timeinout.day");
                String datex = rsx.getString("timeinout.date");
                //                String amStartDBx = rsx.getString("schedule.amStart");
                //                String amInx = rsx.getString("timeinout.amTimeIn");
                //                String amEndDBx = rsx.getString("schedule.amEnd");
                //                String amOutx = rsx.getString("timeinout.amTimeOut");
                //                String pmStartDBx = rsx.getString("schedule.pmStart");
                //                String pmInx = rsx.getString("timeinout.pmTimeIn");
                //                String pmEndDBx = rsx.getString("schedule.pmEnd");
                String pmOutx = rsx.getString("timeinout.pmTimeOut");
                String totalAM = rsx.getString("schedule.amTotal");
                String totalPM = rsx.getString("schedule.pmTotal");
                String totTimex = rsx.getString("schedule.totalTime");
                String wHoursx;

                parser.setTimeZone(TimeZone.getTimeZone("UTC"));

                if (!amEndDB.equals("00:00:00") && !amOut.equals("00:00:00")) {
                    Start = parser.parse(amEndDB);
                    In = parser.parse(amOut);
                    if (Start.after(In)) {
                        amOutDiff = tDiff.timeDiff(amOut, amEndDB);

                        amOutDiffT = parser.parse(amOutDiff);
                        amOutDiffTotal += amOutDiffT.getTime();

                    } else {
                        amOutDiff = "00:00:00";
                    }
                } else {
                    amOutDiff = totalAM;
                    amOutDiffT = parser.parse(amOutDiff);
                    amOutDiffTotal += amOutDiffT.getTime();
                }

                Start = parser.parse(amStartDB);
                In = parser.parse(amIn);
                if (Start.after(In)) {
                    amInDiff = "00:00:00";
                } else if (amOutDiff.equals(totalAM)) {
                    amInDiff = "00:00:00";
                } else {
                    amInDiff = tDiff.timeDiff(amStartDB, amIn);

                    amInDiffT = parser.parse(amInDiff);
                    amInDiffTotal += amInDiffT.getTime();

                }
                if (!pmEndDB.equals("00:00:00") && !pmOut.equals("00:00:00")) {
                    Start = parser.parse(pmEndDB);
                    In = parser.parse(pmOut);
                    if (Start.after(In)) {
                        pmOutDiff = tDiff.timeDiff(pmOut, pmEndDB);

                        pmOutDiffT = parser.parse(pmOutDiff);
                        pmOutDiffTotal += pmOutDiffT.getTime();

                    } else {
                        pmOutDiff = "00:00:00";
                    }
                } else {
                    pmOutDiff = totalPM;
                    pmOutDiffT = parser.parse(pmOutDiff);
                    pmOutDiffTotal += pmOutDiffT.getTime();
                }

                Start = parser.parse(pmStartDB);
                In = parser.parse(pmIn);
                if (Start.after(In)) {
                    pmInDiff = "00:00:00";
                } else if (pmOutDiff.equals(totalPM)) {
                    pmInDiff = "00:00:00";
                } else {
                    pmInDiff = tDiff.timeDiff(pmStartDB, pmIn);

                    pmInDiffT = parser.parse(pmInDiff);
                    pmInDiffTotal += pmInDiffT.getTime();

                }

                Date totH = parser.parse(totTimex);
                long totHTotal = 0;
                totHTotal += totH.getTime();

                Date amInDiffx = parser.parse(amInDiff);
                Date amOutDiffx = parser.parse(amOutDiff);
                Date pmInDiffx = parser.parse(pmInDiff);
                Date pmOutDiffx = parser.parse(pmOutDiff);

                long workedHoursxxx = amInDiffx.getTime() + amOutDiffx.getTime() + pmInDiffx.getTime()
                        + pmOutDiffx.getTime();

                long hoursx = workedHoursxxx / 3600000;
                long minutesx = (workedHoursxxx % 3600000) / 60000;

                wHours = String.format("%02d:%02d", hoursx, minutesx);
                wHoursx = String.format("%02d:%02d", hoursx, minutesx);

                Date dayxxx = new SimpleDateFormat("EEEE").parse(day);
                SimpleDateFormat sdfxxx = new SimpleDateFormat("EEE");
                String newDayxx = sdfxxx.format(dayxxx);
                System.out.println(newDayxx);
                DTRTableCell = new PdfPCell(
                        new Phrase(newDayxx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                Date datexx = new SimpleDateFormat("yyyy-MM-dd").parse(date);
                SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy");
                String newDate = sdf.format(datexx);
                System.out.println(newDate);
                DTRTableCell = new PdfPCell(
                        new Phrase(newDate, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                System.out.println(amIn);
                DTRTableCell = new PdfPCell(
                        new Phrase(amIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                System.out.println(amOut);
                DTRTableCell = new PdfPCell(
                        new Phrase(amOut, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                System.out.println(pmIn);
                DTRTableCell = new PdfPCell(
                        new Phrase(pmIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                System.out.println(pmOut);
                DTRTableCell = new PdfPCell(
                        new Phrase(pmOut, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                System.out.println(totTime);
                DTRTableCell = new PdfPCell(
                        new Phrase(totTime, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                System.out.println(wHours);
                DTRTableCell = new PdfPCell(
                        new Phrase(wHours, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                System.out.println(blank);
                DTRTableCell = new PdfPCell(new Phrase(blank));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                Date dayxx = new SimpleDateFormat("EEEE").parse(dayx);
                SimpleDateFormat sdfxx = new SimpleDateFormat("EEE");
                String newDayx = sdfxx.format(dayxx);
                System.out.println(newDayx);
                DTRTableCell = new PdfPCell(
                        new Phrase(newDayx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                Date datexxx = new SimpleDateFormat("yyyy-MM-dd").parse(datex);
                SimpleDateFormat sdfx = new SimpleDateFormat("dd-MM-yy");
                String newDatex = sdfx.format(datexxx);
                System.out.println(newDatex);
                DTRTableCell = new PdfPCell(
                        new Phrase(newDatex, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                System.out.println(amIn);
                DTRTableCell = new PdfPCell(
                        new Phrase(amIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                System.out.println(amOut);
                DTRTableCell = new PdfPCell(
                        new Phrase(amOut, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                System.out.println(pmIn);
                DTRTableCell = new PdfPCell(
                        new Phrase(pmIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                System.out.println(pmOutx);
                DTRTableCell = new PdfPCell(
                        new Phrase(pmOutx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                System.out.println(totTimex);
                DTRTableCell = new PdfPCell(
                        new Phrase(totTimex, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

                System.out.println(wHoursx);
                DTRTableCell = new PdfPCell(
                        new Phrase(wHoursx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL)));
                DTRTableCell.setBorder(PdfPCell.NO_BORDER);
                DTRTable.addCell(DTRTableCell);

            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
        document.add(dateRecTable);
        document.add(InfoTable);
        document.add(new Paragraph(
                "-----------------------------------------------------------------------               ----------------------------------------------------------------------",
                FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, BaseColor.BLACK)));
        document.add(new Paragraph(
                "                                   Schedule                                                                                     Schedule\n",
                FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK)));
        document.add(SchedTable);
        document.add(new Paragraph(
                "-----------------------------------------------------------------------               ----------------------------------------------------------------------",
                FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, BaseColor.BLACK)));
        document.add(new Paragraph(
                "                             Dailty Time Record                                                                     Dailty Time Record\n",
                FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK)));
        document.add(DTRTable);
        document.add(ICTable);

        try {
            conn = dbC.getConnection();

            PreparedStatement stmtx = conn.prepareStatement("INSERT INTO released"
                    + "(empId, firstDate, lastDate, totalHours, lateUnderTime, workedHours, fileName, salary) VALUES (?,?,?,?,?,?,?,?)");

            stmtx.setString(1, id);
            stmtx.setString(2, fDate);
            stmtx.setString(3, lDate);
            stmtx.setString(4, totalHours);
            stmtx.setString(5, workedHours);
            stmtx.setString(6, totalHours);
            stmtx.setString(7, "Report-" + reportCount + "." + lastRId + "-" + id + ".pdf");
            stmtx.setString(8, salary + "");

            stmtx.executeUpdate();

        } catch (SQLException se) {
            //Handle errors for JDBC
            se.printStackTrace();
        } catch (Exception e) {
            //Handle errors for Class.forName
            e.printStackTrace();
        } finally {
            //finally block used to close resources
            try {
                if (stmt != null)
                    conn.close();
            } catch (SQLException se) {
            } // do nothing
            try {
                if (conn != null)
                    conn.close();
            } catch (SQLException se) {
                se.printStackTrace();
            } //end finally try
        } //end try
        document.close();
    } catch (DocumentException | IOException | SQLException e) {
        JOptionPane.showMessageDialog(null, e);
    } catch (ParseException ex) {
        Logger.getLogger(printPDF.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:be.rheynaerde.poolsheets.PufCompletePoolSheet.java

License:Open Source License

@Override
protected PdfPTable getScoreTable() throws DocumentException {
    final int columnCount = configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2) + 2;
    //one column for each player, an extra column for the numbers and a column for the team marks

    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
    table.setTotalWidth((columnCount) * configuration.getSquareCellSize());
    table.setLockedWidth(true);/*  w  ww .j a  va  2s. co m*/
    float[] widths = new float[columnCount];
    for (int i = 0; i < widths.length; i++) {
        widths[i] = 1f;
    }
    table.setWidths(widths);

    PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2);
    topCell.setFixedHeight(configuration.getSquareCellSize());
    table.addCell(topCell);
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(1)));
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(2)));

    table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1));
    {
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
    }

    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(1), 1));
    for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) {
        if (i == configuration.getNrOfPlayers(1))
            table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM,
                    configuration.getNrOfPlayers(2), 1));

        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        for (int j = 0; j < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); j++) {
            if (i == j) {
                PdfPCell blackCell = getSolidCell();
                table.addCell(blackCell);
            } else {
                table.addCell(configuration.getResult(i, j));
            }
        }
    }

    table.setHorizontalAlignment(Element.ALIGN_RIGHT);
    return table;
}

From source file:be.rheynaerde.poolsheets.PufSingleTeamPoolSheet.java

License:Open Source License

@Override
protected PdfPTable getScoreTable() throws DocumentException {
    final int columnCount = configuration.getNrOfPlayers() + 2;

    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
    table.setTotalWidth((columnCount) * configuration.getSquareCellSize());
    table.setLockedWidth(true);//from w  w  w  .  jav  a  2s .c  om
    float[] widths = new float[columnCount];
    for (int i = 0; i < widths.length; i++) {
        widths[i] = 1f;
    }
    table.setWidths(widths);

    PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2);
    topCell.setFixedHeight(configuration.getSquareCellSize());
    table.addCell(topCell);
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers()));

    table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1));
    {
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
    }

    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(), 1));
    for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        for (int j = 0; j < configuration.getNrOfPlayers(); j++) {
            if (i == j) {
                PdfPCell blackCell = getSolidCell();
                table.addCell(blackCell);
            } else {
                table.addCell(configuration.getResult(i, j));
            }
        }
    }

    table.setHorizontalAlignment(Element.ALIGN_RIGHT);
    return table;
}

From source file:be.rheynaerde.poolsheets.PufTeamPoolSheet.java

License:Open Source License

protected PdfPTable getScoreTable() throws DocumentException {
    //table for scores
    final int columnCount = configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2) + 2;
    //one column for each player, an extra column for the numbers and a column for the team marks

    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    table.setTotalWidth((columnCount) * configuration.getSquareCellSize());
    table.setLockedWidth(true);/* w w  w . j  a  v a 2 s.co m*/
    float[] widths = new float[columnCount];
    for (int i = 0; i < widths.length; i++) {
        widths[i] = 1f;
    }
    table.setWidths(widths);

    PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2);
    topCell.setFixedHeight(configuration.getSquareCellSize());
    table.addCell(topCell);
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(1)));
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(2)));

    table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1));
    {
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
    }

    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(1), 1));
    for (int i = 0; i < configuration.getNrOfPlayers(1); i++) {
        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        if (i == 0) {
            PdfPCell blackCell = getSolidCell();
            blackCell.setColspan(configuration.getNrOfPlayers(1));
            blackCell.setRowspan(configuration.getNrOfPlayers(1));
            table.addCell(blackCell);
        }
        for (int j = 0; j < configuration.getNrOfPlayers(2); j++) {
            table.addCell(configuration.getResult(0, i, 1, j));
        }
    }

    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(2), 1));
    for (int i = 0; i < configuration.getNrOfPlayers(2); i++) {
        table.addCell(getHeaderCell(Integer.toString(configuration.getNrOfPlayers(1) + i + 1)));
        for (int j = 0; j < configuration.getNrOfPlayers(1); j++) {
            table.addCell(configuration.getResult(1, i, 0, j));
        }
        if (i == 0) {
            PdfPCell blackCell = getSolidCell();
            blackCell.setColspan(configuration.getNrOfPlayers(2));
            blackCell.setRowspan(configuration.getNrOfPlayers(2));
            table.addCell(blackCell);
        }
    }
    table.setHorizontalAlignment(Element.ALIGN_RIGHT);
    return table;
}

From source file:beans.ManagedBeanReportes.java

public void inventario() throws DocumentException, IOException {
    FacesContext facexcontext = FacesContext.getCurrentInstance();
    ValueExpression vex = facexcontext.getApplication().getExpressionFactory()
            .createValueExpression(facexcontext.getELContext(), "#{managedBeanLogin}", ManagedBeanLogin.class);
    ManagedBeanLogin beanLogin = (ManagedBeanLogin) vex.getValue(facexcontext.getELContext());

    FacesContext context = FacesContext.getCurrentInstance();

    Document document = new Document(PageSize.A4, 25, 25, 75, 25);//int marginLeft,   int marginRight,   int marginTop,   int marginBottom

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    writer.setPageEvent(new ManagedBeanReportes.Watermark(""));
    if (!document.isOpen()) {
        document.open();//  www . j av a  2  s  . c om
    }

    try {

        ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
        //String imageUrl1 = extContext.getRealPath("//resources//images/logo0002.png");
        //Image welladigital = Image.getInstance(imageUrl1);
        //welladigital.setAbsolutePosition(377f, 760f);
        //welladigital.scalePercent(40);
        //document.add(welladigital);

        //crear tabla PARA NOMBRE DEL AO
        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100);
        table.setTotalWidth(450f);
        // table.setTotalWidth(540f);
        table.setLockedWidth(true);
        float[] headerWidths = { 120, 20, 310 };
        table.setWidths(headerWidths);
        table.getDefaultCell();

        SimpleDateFormat formato = new SimpleDateFormat("EEEE dd MMMM YYYY");
        StringBuilder cadena = new StringBuilder(formato.format(fecha_inicio));

        Chunk underline = new Chunk("FECHA DE INVENTARIO:" + cadena.toString().toUpperCase(), bigFont12);
        underline.setUnderline(0.2f, -2f); //0.1 thick, -2 y-location
        PdfPCell table5 = new PdfPCell(new Paragraph(underline));
        table5.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
        table5.setColspan(3);
        table5.setBorder(Rectangle.NO_BORDER);
        table.addCell(table5);

        document.add(table);

        document.add(new Paragraph("\n", pequeFont));

        PdfPCell table2 = new PdfPCell();

        table2 = new PdfPCell(
                new Paragraph(beanLogin.getObjetoEmpleado().getTienda().getNombreTienda(), pequeFont));
        table2.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
        table2.setColspan(3);
        table2.setBorder(Rectangle.NO_BORDER);
        table = new PdfPTable(3);
        table.setWidthPercentage(100);
        table.setTotalWidth(450f);
        table.setLockedWidth(true);
        table.setWidths(headerWidths);
        table.getDefaultCell();
        table.addCell(table2);
        document.add(table);

        document.add(new Paragraph("\n", pequeFont));

        document.add(traerSubtabla(beanLogin.getObjetoEmpleado().getTienda()));
        formato = new SimpleDateFormat("yyyy-MM-dd");
        cadena = new StringBuilder(formato.format(fecha_inicio));

        //document.add(traerSubtabla02(cadena.toString()));
        document.add(new Paragraph("\n", pequeFont));
        ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
        String ctxPath = ((ServletContext) ctx.getContext()).getContextPath();
        document.close();
        formato = new SimpleDateFormat("dd_MM_yyyy");
        cadena = new StringBuilder(formato.format(fecha_inicio));
        String fileName = cadena.toString();

        writePDFToResponse(context.getExternalContext(), baos, fileName);
        context.responseComplete();

    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:beans.ManagedBeanReportes.java

public PdfPTable traerSubtabla(Tienda t) throws DocumentException {
    PdfPTable tabla_PesajeDetalle = new PdfPTable(4);
    tabla_PesajeDetalle.setWidthPercentage(100);
    tabla_PesajeDetalle.setTotalWidth(450f);
    tabla_PesajeDetalle.setLockedWidth(true);

    tabla_PesajeDetalle.setWidths(anchocol03);
    tabla_PesajeDetalle.getDefaultCell();

    PdfPCell Cell_Headers = new PdfPCell(new Paragraph("PRODUCTO", titulopequeFont));
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);

    tabla_PesajeDetalle.addCell(Cell_Headers);

    Cell_Headers = new PdfPCell(new Paragraph("UBICACIONES", titulopequeFont));
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    tabla_PesajeDetalle.addCell(Cell_Headers);

    Cell_Headers = new PdfPCell(new Paragraph("MINIMO", titulopequeFont));
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    tabla_PesajeDetalle.addCell(Cell_Headers);

    Cell_Headers = new PdfPCell(new Paragraph("STOCK TOTAL", titulopequeFont));
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    tabla_PesajeDetalle.addCell(Cell_Headers);

    for (StockProductoTiendaOrigen det : stockProductoTiendaOrigenFacade.lista_stock_tienda(t)) {
        tabla_PesajeDetalle.addCell(traerCelda(det.getProducto().getNombreProducto()));
        String ubicaciones_ = "";
        for (DetalleAlmacenProductos p : detalleAlmacenProductosFacade.lista_para_stock_tienda(t,
                det.getProducto())) {/*from  w  w w . j a v  a2  s  . c  o m*/
            if (p.getUbicacionFisica().getIdUbicacionFisica() > 1) {
                ubicaciones_ = p.getUbicacionFisica().getNombreUbicacionFisica() + ";" + ubicaciones_;
            }
        }
        tabla_PesajeDetalle.addCell(traerCelda(ubicaciones_));
        tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidadMinimaStock())));
        tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidad())));
    }
    return tabla_PesajeDetalle;
}

From source file:billerfx.FXMLBillController.java

File generatePDF() {
    File fi = null;//from   w  w  w .  j  av  a 2s .co  m
    try {
        Stage gg = ((Stage) imv.getParent().getScene().getWindow());
        fi = File.createTempFile("billerfx_" + gg.getTitle(), ".pdf");
        fi.deleteOnExit();

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(fi));
        Rectangle r = new RectangleReadOnly(207, 575);
        document.setPageSize(r);
        document.setMargins(15, 15, 0, 0);
        document.open();
        Font fontbold = FontFactory.getFont("Times-Roman", 10, Font.NORMAL);
        Font fontbold2 = FontFactory.getFont("Times-Roman", 9, Font.NORMAL);

        String[] ll = Database.getCurrentSettings();
        String ss = "-----------------------------------------------------\n";
        ss += ll[0] + "\nAddress: " + ll[1] + "\nPhone: " + ll[2] + "\n";
        String kk = Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM ? "AM"
                : (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.PM ? "PM" : "");
        ss += Calendar.getInstance().get(Calendar.DATE) + "/" + (1 + Calendar.getInstance().get(Calendar.MONTH))
                + "/" + Calendar.getInstance().get(Calendar.YEAR) + " at "
                + Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE)
                + " " + kk + "\n";
        ss += "Table No. " + c.getText() + "     Bill No. " + a.getText() + "\n";
        ss += "-----------------------------------------------------\n";
        Paragraph para = new Paragraph(ss, fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        float[] columnWidths = { 3f, 1f };
        table.setWidths(columnWidths);
        PdfPCell defaultCell = table.getDefaultCell();
        defaultCell.setBorder(PdfPCell.NO_BORDER);

        ObservableList ob = map.get(Integer.parseInt(gg.getTitle()));
        for (int i = 0; i < ob.size(); i++) {
            Item2 ii = (Item2) ob.get(i);
            String s1 = ii.getQuantity() + " x " + ii.getName();
            String s2 = "Rs. " + ii.getTotal();
            Paragraph para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            Paragraph para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            PdfPCell cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            PdfPCell cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }
        document.add(table);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(columnWidths);
        defaultCell = table.getDefaultCell();
        defaultCell.setBorder(PdfPCell.NO_BORDER);

        String s1 = "Total:";
        String s2 = "Rs. " + h.getText();
        Paragraph para1 = new Paragraph(s1, fontbold2);
        para1.setAlignment(Paragraph.ALIGN_LEFT);
        Paragraph para2 = new Paragraph(s2, fontbold2);
        para2.setAlignment(Paragraph.ALIGN_RIGHT);
        PdfPCell cell1 = new PdfPCell(para1);
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        PdfPCell cell2 = new PdfPCell(para2);
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell1);
        table.addCell(cell2);

        if (Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()) > 0.0) {
            s1 = "Discount:";
            s2 = "Rs. " + BillerFX.df.format(Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()));
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        if (ll[7].equals("1")) {
            s1 = ll[3];
            s2 = "Rs. " + k.getText();
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        if (ll[8].equals("1")) {
            s1 = ll[4];
            s2 = "Rs. " + l.getText();
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        s1 = "Grand Total:";
        s2 = "Rs. " + m.getText();
        para1 = new Paragraph(s1, fontbold2);
        para1.setAlignment(Paragraph.ALIGN_LEFT);
        para2 = new Paragraph(s2, fontbold2);
        para2.setAlignment(Paragraph.ALIGN_RIGHT);
        cell1 = new PdfPCell(para1);
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell2 = new PdfPCell(para2);
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell1);
        table.addCell(cell2);

        document.add(table);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        fontbold2 = FontFactory.getFont("Times-Roman", 8, Font.NORMAL);
        para = new Paragraph(
                "Thank You.\nThis invoice was created using BillerFX.\n (BillerFX Contact: ayushmaanbhav1008@gmail.com)\n",
                fontbold2);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        document.close();
    } catch (Exception mm) {
    }
    return fi;
}

From source file:bladwin.web.reg.regPDF.java

private PdfPTable genAthleteInfo(customerRegBean a, customerBean c) {
    float[] widths = { 0.30f, 0.70f };
    PdfPTable table = new PdfPTable(widths);
    table.getDefaultCell().setBorder(0);
    PdfPCell cell1 = new PdfPCell(), cell2 = new PdfPCell();
    cell1.setPhrase(pdfRptMgr.getRptFont("Athlete Name", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(a.getFullname()));

    table.addCell(cell1);// w  ww  . j ava  2s. c  o m
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("School", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(a.getSchool()));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("Date of Birth", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(a.getDobStr()));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("Cell #", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(c.getCell()));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("E-Mail", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(c.getEMail()));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("Any Health Concerns?", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(a.getRegNote()));
    table.addCell(cell1);
    table.addCell(cell2);

    cell1.setPhrase(pdfRptMgr.getRptFont("Emergency Contact", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(a.getContact()));
    table.addCell(cell1);
    table.addCell(cell2);

    return table;
}

From source file:bladwin.web.reg.regPDF.java

private PdfPTable genParentInfo(customerBean c) {
    float[] widths = { 0.20f, 0.80f };
    PdfPTable table = new PdfPTable(widths);
    table.getDefaultCell().setBorder(0);
    PdfPCell cell1 = new PdfPCell(), cell2 = new PdfPCell();
    cell1.setPhrase(pdfRptMgr.getRptFont("Parent Name", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(c.getLastName() + ", " + c.getFirstName()));
    table.addCell(cell1);/*from w  ww.j  a  v a2 s  . c o m*/
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("Address", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(getAddress(c)));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("Cell #", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(c.getCell()));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("Home #", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(c.getHmPhone()));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("E-Mail", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(c.getEMail()));
    table.addCell(cell1);
    table.addCell(cell2);
    return table;
}