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

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

Introduction

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

Prototype

public void setWidthPercentage(final float widthPercentage) 

Source Link

Document

Sets the width percentage that the table will occupy in the page.

Usage

From source file:generatepayslipbyaccz.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// w w w .  j ava2  s .co m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, ClassNotFoundException {
    // setting the content type
    response.setContentType("application/pdf");
    try {
        HttpSession session = request.getSession();
        if (session.getAttribute("username") != null) {
            // Get the text that will be added to the PDF

            String month = request.getParameter("month");
            String year = request.getParameter("year");
            String id = request.getParameter("empid");
            //  System.out.println(id);
            //   String text = request.getParameter("text");
            //  if (text == null || text.trim().length() == 0) {
            //       text = "You didn't enter any text.";
            //  }
            //String id="Ultimate01";    
            Class.forName("com.mysql.jdbc.Driver").newInstance();

            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/payroll123", "root", "");

            PreparedStatement ps = con.prepareStatement("SELECT * from employee where id=?");
            ps.setString(1, id);
            //   ps.setString(2, pass);
            PreparedStatement ps1 = con
                    .prepareStatement("SELECT * from payslip where employeeid=? and month=? and year=?");
            ps1.setString(1, id);
            ps1.setString(2, month);
            ps1.setString(3, year);

            PreparedStatement ps2 = con
                    .prepareStatement("SELECT * from `leave` where employeeid=? and month=? and year=?");
            ps2.setString(1, id);
            ps2.setString(2, month);
            ps2.setString(3, year);

            ResultSet rs2 = ps2.executeQuery();
            rs2.next();

            ResultSet rs = ps.executeQuery();
            rs.next();
            ResultSet rs1 = ps1.executeQuery();
            if (rs1.next() == false) {
                response.sendRedirect("generatepayslipbyaccz.jsp?id=Payslip of " + month + "/" + year
                        + " is not generated OR Record of this Payslip is not available in our Database");
            }
            // step 1

            //System.out.println("sssssssssssssssssss");

            Document document = new Document();
            // step 2
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PdfWriter.getInstance(document, baos);

            Font font0 = new Font(Font.FontFamily.TIMES_ROMAN, 11);
            Font font1 = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD);
            Font font2 = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD);
            Font font3 = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD);
            Font font4 = new Font(Font.FontFamily.HELVETICA, 10);
            Font font5 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD);
            Font font6 = new Font(Font.FontFamily.HELVETICA, 12);

            //font1.setColor(BaseColor.WHITE);
            BaseColor myColor = WebColors.getRGBColor("#F78181");
            BaseColor myColor1 = WebColors.getRGBColor("#FAFAFA");

            //step 3
            document.open();
            // step 3.5
            PdfPTable table1 = new PdfPTable(3); // 1 columns.
            PdfPCell cell00 = new PdfPCell(new Paragraph("Payslip\nFEB-2015", font2));
            cell00.setBorder(PdfPCell.NO_BORDER);
            cell00.setPaddingTop(18);
            PdfPCell cell01 = new PdfPCell(new Paragraph(""));
            cell01.setBorder(PdfPCell.NO_BORDER);

            Image image = Image.getInstance("cc.jpg");
            PdfPCell cell0 = new PdfPCell(image, true);
            cell0.setBorder(PdfPCell.NO_BORDER);

            // cell0.setHorizontalAlignment(Element.ALIGN_RIGHT);
            //PdfPCell cell1 = new PdfPCell(new Paragraph("Mr. NILESH POPATBHAI LATHIYA"));
            table1.addCell(cell00);
            table1.addCell(cell01);
            table1.addCell(cell0);
            //  table1.addCell(cell1);
            //            table.addCell(cell2);
            //          table.addCell(cell3);
            table1.setWidthPercentage(100);
            table1.setSpacingAfter(2f);
            //table1.setSpacingBefore(20f);

            //table1.setSpacingAfter(10f);

            document.add(table1);
            //  table1.setWidthPercentage(100);
            PdfPTable table2 = new PdfPTable(6); // 3 columns.
            table2.setWidthPercentage(100);
            PdfPCell cell11 = new PdfPCell(new Paragraph(
                    rs.getString(2) + " " + rs.getString(3) + " " + rs.getString(4) + " " + rs.getString(5),
                    font0));
            cell11.setColspan(6);
            //cell11.setBorder(PdfPCell.NO_BORDER);
            cell11.setLeading(10f, 0f);
            cell11.setBorderWidth(1f);
            cell11.setPadding(4);
            cell11.setBackgroundColor(myColor1);
            PdfPCell cell12 = new PdfPCell(new Paragraph("Employee Details", font1));
            cell12.setColspan(2);

            cell12.setBorderWidth(1f);
            cell12.setLeading(10f, 0f);
            cell12.setPadding(4);
            cell12.setBackgroundColor(myColor);
            PdfPCell cell13 = new PdfPCell(new Paragraph("Payment & Leave Details", font1));
            cell13.setColspan(2);
            cell13.setLeading(10f, 0f);
            cell13.setPadding(4);
            cell13.setBorderWidth(1f);
            cell13.setBackgroundColor(myColor);
            // cell11.setLeading(15f, 1.5f);
            PdfPCell cell14 = new PdfPCell(new Paragraph("Location Details", font1));
            cell14.setColspan(2);
            cell14.setLeading(10f, 0f);
            cell14.setPadding(4);
            cell14.setBorderWidth(1f);
            cell14.setBackgroundColor(myColor);
            //            PdfPTable nestedTable1 = new PdfPTable(2);
            //    nestedTable1.addCell(new Paragraph("Emp No."));
            //   nestedTable1.addCell(new Paragraph("379666"));

            //      cell41.addElement(nestedTable1);
            table2.addCell(cell11);
            table2.addCell(cell12);
            table2.addCell(cell13);
            table2.addCell(cell14);

            PdfPCell cell15 = new PdfPCell(new Paragraph("Emp ID.", font3));
            //cell15.setLeading(10f, 0f);
            cell15.setPadding(3);
            cell15.setBorderWidth(1f);
            cell15.setBackgroundColor(myColor1);
            PdfPCell cell16 = new PdfPCell(new Paragraph(rs.getString(1), font4));
            //  cell16.setLeading(10f, 0f);
            cell16.setPadding(3);
            cell16.setBorderWidth(1f);
            cell16.setBackgroundColor(myColor1);
            PdfPCell cell17 = new PdfPCell(new Paragraph("Bank Name", font3));
            //cell17.setLeading(10f, 0f);
            cell17.setPadding(3);
            cell17.setBorderWidth(1f);
            cell17.setBackgroundColor(myColor1);
            PdfPCell cell18 = new PdfPCell(new Paragraph(rs.getString(11), font4));
            //cell18.setLeading(10f, 0f);
            cell18.setPadding(3);
            cell18.setBorderWidth(1f);
            cell18.setBackgroundColor(myColor1);
            PdfPCell cell19 = new PdfPCell(new Paragraph("Location", font3));
            //cell19.setLeading(10f, 0f);
            cell19.setPadding(3);
            cell19.setBorderWidth(1f);
            cell19.setBackgroundColor(myColor1);
            PdfPCell cell20 = new PdfPCell(new Paragraph(rs.getString(13), font4));
            //cell20.setLeading(10f, 0f);
            cell20.setPadding(3);
            cell20.setBorderWidth(1f);
            cell20.setBackgroundColor(myColor1);

            table2.addCell(cell15);
            table2.addCell(cell16);
            table2.addCell(cell17);
            table2.addCell(cell18);
            table2.addCell(cell19);
            table2.addCell(cell20);

            PdfPCell cell21 = new PdfPCell(new Paragraph("Dsgn.", font3));
            //cell21.setLeading(10f, 0f);
            cell21.setPadding(3);
            cell21.setBorderWidth(1f);
            cell21.setBackgroundColor(myColor1);
            PdfPCell cell22 = new PdfPCell(new Paragraph(rs.getString(9), font4));
            //  cell22.setLeading(10f, 0f);
            cell22.setPadding(3);
            cell22.setBorderWidth(1f);
            cell22.setBackgroundColor(myColor1);
            PdfPCell cell23 = new PdfPCell(new Paragraph("Acc No.", font3));
            //cell23.setLeading(10f, 0f);
            cell23.setPadding(3);
            cell23.setBorderWidth(1f);
            cell23.setBackgroundColor(myColor1);

            int accno = Integer.parseInt(rs.getString(12));
            String accno1[] = new String[4];
            for (int i = 0; i < 4; i++) {
                accno1[i] = Integer.toString(accno % 10);
                accno /= 10;
            }

            PdfPCell cell24 = new PdfPCell(new Paragraph(
                    "XXXXXXX" + accno1[3] + "" + accno1[2] + "" + accno1[1] + "" + accno1[0], font4));
            //cell24.setLeading(10f, 0f);
            cell24.setPadding(3);
            cell24.setBorderWidth(1f);
            cell24.setBackgroundColor(myColor1);
            PdfPCell cell25 = new PdfPCell(new Paragraph("Base Br.", font3));
            //cell25.setLeading(10f, 0f);
            cell25.setPadding(3);
            cell25.setBorderWidth(1f);
            cell25.setBackgroundColor(myColor1);
            PdfPCell cell26 = new PdfPCell(new Paragraph("CC - Ahmedabad", font4));
            //cell26.setLeading(10f, 0f);
            cell26.setPadding(3);
            cell26.setBorderWidth(1f);
            cell26.setBackgroundColor(myColor1);

            table2.addCell(cell21);
            table2.addCell(cell22);
            table2.addCell(cell23);
            table2.addCell(cell24);
            table2.addCell(cell25);
            table2.addCell(cell26);

            PdfPCell cell27 = new PdfPCell(new Paragraph("Grade", font3));
            //cell27.setLeading(10f, 0f);
            cell27.setPadding(3);
            cell27.setBorderWidth(1f);
            cell27.setBackgroundColor(myColor1);
            PdfPCell cell28 = new PdfPCell(new Paragraph("C2", font4));
            //  cell28.setLeading(10f, 0f);
            cell28.setPadding(3);
            cell28.setBorderWidth(1f);
            cell28.setBackgroundColor(myColor1);
            PdfPCell cell29 = new PdfPCell(new Paragraph("Days paid", font3));
            //cell29.setLeading(10f, 0f);
            cell29.setPadding(3);
            cell29.setBorderWidth(1f);
            cell29.setBackgroundColor(myColor1);
            PdfPCell cell30 = new PdfPCell(new Paragraph(Integer.toString(rs1.getInt(5)), font4));
            //cell30.setLeading(10f, 0f);
            cell30.setPadding(3);
            cell30.setBorderWidth(1f);
            cell30.setBackgroundColor(myColor1);
            PdfPCell cell31 = new PdfPCell(new Paragraph("Depute Br.", font3));
            //cell31.setLeading(10f, 0f);
            cell31.setPadding(3);
            cell31.setBorderWidth(1f);
            cell31.setBackgroundColor(myColor1);
            PdfPCell cell32 = new PdfPCell(new Paragraph("CC - Ahmedabad", font4));
            //cell32.setLeading(10f, 0f);
            cell32.setPadding(3);
            cell32.setBorderWidth(1f);
            cell32.setBackgroundColor(myColor1);

            table2.addCell(cell27);
            table2.addCell(cell28);
            table2.addCell(cell29);
            table2.addCell(cell30);
            table2.addCell(cell31);
            table2.addCell(cell32);

            PdfPCell cell33 = new PdfPCell(new Paragraph("PAN", font3));
            //cell33.setLeading(10f, 0f);
            cell33.setPadding(3);
            cell33.setBorderWidth(1f);
            cell33.setBackgroundColor(myColor1);
            PdfPCell cell34 = new PdfPCell(new Paragraph("XXXXXXX792E", font4));
            //  cell34.setLeading(10f, 0f);
            cell34.setPadding(3);
            cell34.setBorderWidth(1f);
            cell34.setBackgroundColor(myColor1);
            PdfPCell cell35 = new PdfPCell(new Paragraph("Leave Balance", font3));
            //cell35.setLeading(10f, 0f);
            cell35.setPadding(3);
            cell35.setBorderWidth(1f);
            cell35.setBackgroundColor(myColor1);
            // PdfPCell cell36 = new PdfPCell(new Paragraph("EL X SL X CL X",font4));
            PdfPCell cell36 = new PdfPCell(new Paragraph(
                    "EL " + rs2.getInt(1) + "  SL " + rs2.getInt(2) + "  CL " + rs2.getInt(3), font4));
            //cell36.setLeading(10f, 0f);
            cell36.setPadding(3);
            cell36.setBorderWidth(1f);
            cell36.setBackgroundColor(myColor1);
            PdfPCell cell37 = new PdfPCell(new Paragraph(" WON/SWON", font3));
            //cell37.setLeading(10f, 0f);
            cell37.setPadding(3);
            cell37.setBorderWidth(1f);
            cell37.setBackgroundColor(myColor1);
            PdfPCell cell38 = new PdfPCell(new Paragraph("2616141", font4));
            //cell38.setLeading(10f, 0f);
            cell38.setPadding(3);
            cell38.setBorderWidth(1f);
            cell38.setBackgroundColor(myColor1);

            table2.addCell(cell33);
            table2.addCell(cell34);
            table2.addCell(cell35);
            table2.addCell(cell36);
            table2.addCell(cell37);
            table2.addCell(cell38);

            table2.setSpacingAfter(12f);

            document.add(table2);

            PdfPTable table3 = new PdfPTable(5); // 5 columns.
            table3.setWidthPercentage(100);

            PdfPCell cell39 = new PdfPCell(new Paragraph("Earnings", font1));
            cell39.setLeading(10f, 0f);
            cell39.setPadding(4);
            cell39.setBorderWidth(1f);
            cell39.setBackgroundColor(myColor);
            PdfPCell cell40 = new PdfPCell(new Paragraph("Arrears (INR)", font1));
            cell40.setLeading(10f, 0f);
            cell40.setPadding(4);
            cell40.setBorderWidth(1f);
            cell40.setBackgroundColor(myColor);
            PdfPCell cell41 = new PdfPCell(new Paragraph("Current (INR)", font1));
            cell41.setLeading(10f, 0f);
            cell41.setPadding(4);
            cell41.setBorderWidth(1f);
            cell41.setBackgroundColor(myColor);
            PdfPCell cell42 = new PdfPCell(new Paragraph("Deductions", font1));
            cell42.setLeading(10f, 0f);
            cell42.setPadding(4);
            cell42.setBorderWidth(1f);
            cell42.setBackgroundColor(myColor);
            PdfPCell cell43 = new PdfPCell(new Paragraph("Amount (INR)", font1));
            cell43.setLeading(10f, 0f);
            cell43.setPadding(4);
            cell43.setBorderWidth(1f);
            cell43.setBackgroundColor(myColor);

            table3.addCell(cell39);
            table3.addCell(cell40);
            table3.addCell(cell41);
            table3.addCell(cell42);
            table3.addCell(cell43);

            String[] sal = new String[10];
            sal[0] = "Basic Salary";
            sal[1] = "House Rent Allowance";
            sal[2] = "Medical Allowance";
            sal[3] = "Travelling Allowance";
            sal[4] = "Personal Allowance";
            sal[5] = "City Allowance";
            sal[6] = "Performance Pay";
            sal[7] = "Provident Fund";
            sal[8] = "Professional Tax";
            sal[9] = "Extra Leaves";

            Float[] val = new Float[10];
            val[0] = rs1.getFloat(4);
            val[1] = 6000.00f;
            val[2] = 1000.00f;
            val[3] = 1000.00f;
            val[4] = val[0] / 2;
            val[5] = 1000.00f;
            val[6] = val[4];
            val[7] = val[0] * 12 / 100;
            val[8] = 0.00f;
            if ((val[0] + val[4] + val[6]) * 12 > 250000.00f) {
                val[8] = (val[0] + val[4] + val[6]) / 10;
            }
            val[9] = 0.0f;
            if (rs2.getInt(1) < 0)
                val[9] -= (rs2.getInt(1) * val[0]) / 30;
            if (rs2.getInt(2) < 0)
                val[9] -= rs2.getInt(2) * val[0] / 30;
            if (rs2.getInt(3) < 0)
                val[9] -= rs2.getInt(3) * val[0] / 30;

            for (int i = 0; i < 7; i++) {
                PdfPCell cell44 = new PdfPCell(new Paragraph(sal[i], font3));
                //cell27.setLeading(10f, 0f);
                cell44.setPadding(3);
                cell44.setBorderWidth(1f);
                cell44.setBackgroundColor(myColor1);
                PdfPCell cell45 = new PdfPCell(new Paragraph("", font4));
                //  cell45.setLeading(10f, 0f);
                cell45.setPadding(3);
                cell45.setBorderWidth(1f);
                cell45.setBackgroundColor(myColor1);
                PdfPCell cell46 = new PdfPCell(new Paragraph(val[i].toString(), font3));
                //cell46.setLeading(10f, 0f);
                cell46.setHorizontalAlignment(Element.ALIGN_RIGHT);
                cell46.setPadding(3);
                cell46.setBorderWidth(1f);
                cell46.setBackgroundColor(myColor1);

                table3.addCell(cell44);
                table3.addCell(cell45);
                table3.addCell(cell46);

                if (i == 0 || i == 1 || i == 2) {
                    PdfPCell cell47 = new PdfPCell(new Paragraph(sal[7 + i], font4));
                    //cell47.setLeading(10f, 0f);
                    cell47.setPadding(3);
                    cell47.setBorderWidth(1f);
                    cell47.setBackgroundColor(myColor1);
                    table3.addCell(cell47);
                    PdfPCell cell48 = new PdfPCell(new Paragraph(val[i + 7].toString(), font3));
                    //cell48.setLeading(10f, 0f);
                    cell48.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    cell48.setPadding(3);
                    cell48.setBorderWidth(1f);
                    cell48.setBackgroundColor(myColor1);
                    table3.addCell(cell48);
                } else {
                    PdfPCell cell47 = new PdfPCell(new Paragraph("", font4));
                    cell47.setBorder(PdfPCell.NO_BORDER);
                    cell47.setBorderWidthRight(1f);
                    cell47.setColspan(2);
                    table3.addCell(cell47);
                }

            }

            PdfPCell cell48 = new PdfPCell(new Paragraph("", font4));
            //cell48.setBorder(PdfPCell.NO_BORDER);
            cell48.setColspan(3);
            table3.addCell(cell48);

            PdfPCell cell49 = new PdfPCell(new Paragraph("", font4));
            //cell49.setBorder(PdfPCell.NO_BORDER);
            cell49.setColspan(2);
            table3.addCell(cell49);
            table3.addCell(cell48);
            table3.addCell(cell49);
            table3.addCell(cell48);
            table3.addCell(cell49);
            table3.addCell(cell48);
            table3.addCell(cell49);

            PdfPCell cell50 = new PdfPCell(new Paragraph("Total Earnings (Current + Arrears)", font3));
            //cell27.setLeading(10f, 0f);
            cell50.setColspan(2);
            cell50.setPadding(3);
            cell50.setBorderWidth(1f);
            cell50.setBackgroundColor(myColor1);
            table3.addCell(cell50);

            float a = 0.0f;
            for (int i = 0; i < 7; i++) {
                a += val[i];
            }
            PdfPCell cell55 = new PdfPCell(new Paragraph(Float.toString(a), font3));
            //cell27.setLeading(10f, 0f);
            cell55.setPadding(3);
            cell55.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell55.setBorderWidth(1f);
            cell55.setBackgroundColor(myColor1);
            table3.addCell(cell55);

            PdfPCell cell51 = new PdfPCell(new Paragraph("Total Deductions", font3));
            //cell27.setLeading(10f, 0f);
            //cell51.setColspan(3);
            cell51.setPadding(3);
            cell51.setBorderWidth(1f);
            cell51.setBackgroundColor(myColor1);
            table3.addCell(cell51);

            float b = val[7] + val[8] + val[9];

            PdfPCell cell56 = new PdfPCell(new Paragraph(Float.toString(b), font3));
            //cell27.setLeading(10f, 0f);
            //cell56.setColspan(3);
            cell56.setPadding(3);
            cell56.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell56.setBorderWidth(1f);
            cell56.setBackgroundColor(myColor1);
            table3.addCell(cell56);

            table3.setSpacingAfter(12f);

            document.add(table3);

            PdfPTable table4 = new PdfPTable(5); // 2 columns.
            table4.setWidthPercentage(100);

            PdfPCell cell54 = new PdfPCell(new Paragraph("", font3));
            cell54.setBorder(PdfPCell.NO_BORDER);
            cell54.setColspan(3);
            table4.addCell(cell54);

            PdfPCell cell52 = new PdfPCell(new Paragraph("Net Pay", font5));
            cell52.setLeading(10f, 0f);
            // cell52.setBorder(PdfPCell.ALIGN_CENTER);
            cell52.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell52.setVerticalAlignment(Element.ALIGN_CENTER);

            cell52.setPadding(6f);
            cell52.setBorderWidth(1f);
            cell52.setBackgroundColor(myColor);
            table4.addCell(cell52);

            PdfPCell cell53 = new PdfPCell(new Paragraph("" + (a - b), font6));
            cell53.setLeading(10f, 0f);
            cell53.setPadding(6f);
            cell53.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell53.setVerticalAlignment(Element.ALIGN_CENTER);
            cell53.setBorderWidth(1f);

            table4.addCell(cell53);

            document.add(table4);

            // step 4
            // document.add(new Paragraph(String.format(
            //         "You have submitted the following text using the %s method:%s",
            //        request.getMethod(),uname)));
            //   document.add(new Paragraph(text));
            // step 5
            document.close();

            // setting some response headers
            response.setHeader("Expires", "0");
            response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
            response.setHeader("Pragma", "public");

            // the contentlength
            response.setContentLength(baos.size());
            // write ByteArrayOutputStream to the ServletOutputStream
            OutputStream os = response.getOutputStream();
            baos.writeTo(os);
            os.flush();
            os.close();
        } else {
            response.sendRedirect("index.jsp?id=Your session may be expired. You have to login first");

        }
    } catch (Exception e) {
        //       throw new IOException(e.getMessage());
        System.out.println(e);
        System.out.println("sssssssssssssssssss");

    }
}

From source file:generatepayslip.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   ww  w . j av  a 2  s . c om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, ClassNotFoundException {
    // setting the content type
    response.setContentType("application/pdf");
    try {
        HttpSession session = request.getSession();
        if (session.getAttribute("username") != null) {
            // Get the text that will be added to the PDF

            String month = request.getParameter("month");
            String year = request.getParameter("year");
            String id = (String) session.getAttribute("id");
            //  System.out.println(id);
            //   String text = request.getParameter("text");
            //  if (text == null || text.trim().length() == 0) {
            //       text = "You didn't enter any text.";
            //  }
            //String id="Ultimate01";    
            Class.forName("com.mysql.jdbc.Driver").newInstance();

            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/payroll123", "root", "");

            PreparedStatement ps = con.prepareStatement("SELECT * from employee where id=?");
            ps.setString(1, id);
            //   ps.setString(2, pass);
            PreparedStatement ps1 = con
                    .prepareStatement("SELECT * from payslip where employeeid=? and month=? and year=?");
            ps1.setString(1, id);
            ps1.setString(2, month);
            ps1.setString(3, year);

            //  PreparedStatement ps2 = con.prepareStatement("SELECT * from leave ");
            PreparedStatement ps2 = con
                    .prepareStatement("SELECT * from `leave` where employeeid=? and month=? and year=?");
            ps2.setString(1, id);
            ps2.setString(2, month);
            ps2.setString(3, year);
            //    
            ResultSet rs = ps.executeQuery();
            rs.next();
            ResultSet rs1 = ps1.executeQuery();
            ResultSet rs2 = ps2.executeQuery();
            rs2.next();
            if (rs1.next() == false) {
                response.sendRedirect("generatepayslip.jsp?id=Payslip of " + month + "/" + year
                        + " is not generated OR Record of this Payslip is not available in our Database");
            }
            // step 1

            //System.out.println("sssssssssssssssssss");

            Document document = new Document();
            // step 2
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PdfWriter.getInstance(document, baos);

            Font font0 = new Font(Font.FontFamily.TIMES_ROMAN, 11);
            Font font1 = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD);
            Font font2 = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD);
            Font font3 = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD);
            Font font4 = new Font(Font.FontFamily.HELVETICA, 10);
            Font font5 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD);
            Font font6 = new Font(Font.FontFamily.HELVETICA, 12);

            //font1.setColor(BaseColor.WHITE);
            BaseColor myColor = WebColors.getRGBColor("#F78181");
            BaseColor myColor1 = WebColors.getRGBColor("#FAFAFA");

            //step 3
            document.open();
            // step 3.5
            PdfPTable table1 = new PdfPTable(3); // 1 columns.
            PdfPCell cell00 = new PdfPCell(new Paragraph("Payslip\nFEB-2015", font2));
            cell00.setBorder(PdfPCell.NO_BORDER);
            cell00.setPaddingTop(18);
            PdfPCell cell01 = new PdfPCell(new Paragraph(""));
            cell01.setBorder(PdfPCell.NO_BORDER);

            Image image = Image.getInstance("cc.jpg");
            PdfPCell cell0 = new PdfPCell(image, true);
            cell0.setBorder(PdfPCell.NO_BORDER);

            // cell0.setHorizontalAlignment(Element.ALIGN_RIGHT);
            //PdfPCell cell1 = new PdfPCell(new Paragraph("Mr. NILESH POPATBHAI LATHIYA"));
            table1.addCell(cell00);
            table1.addCell(cell01);
            table1.addCell(cell0);
            //  table1.addCell(cell1);
            //            table.addCell(cell2);
            //          table.addCell(cell3);
            table1.setWidthPercentage(100);
            table1.setSpacingAfter(2f);
            //table1.setSpacingBefore(20f);

            //table1.setSpacingAfter(10f);

            document.add(table1);
            //  table1.setWidthPercentage(100);
            PdfPTable table2 = new PdfPTable(6); // 3 columns.
            table2.setWidthPercentage(100);
            PdfPCell cell11 = new PdfPCell(new Paragraph((String) session.getAttribute("username"), font0));
            cell11.setColspan(6);
            //cell11.setBorder(PdfPCell.NO_BORDER);
            cell11.setLeading(10f, 0f);
            cell11.setBorderWidth(1f);
            cell11.setPadding(4);
            cell11.setBackgroundColor(myColor1);
            PdfPCell cell12 = new PdfPCell(new Paragraph("Employee Details", font1));
            cell12.setColspan(2);

            cell12.setBorderWidth(1f);
            cell12.setLeading(10f, 0f);
            cell12.setPadding(4);
            cell12.setBackgroundColor(myColor);
            PdfPCell cell13 = new PdfPCell(new Paragraph("Payment & Leave Details", font1));
            cell13.setColspan(2);
            cell13.setLeading(10f, 0f);
            cell13.setPadding(4);
            cell13.setBorderWidth(1f);
            cell13.setBackgroundColor(myColor);
            // cell11.setLeading(15f, 1.5f);
            PdfPCell cell14 = new PdfPCell(new Paragraph("Location Details", font1));
            cell14.setColspan(2);
            cell14.setLeading(10f, 0f);
            cell14.setPadding(4);
            cell14.setBorderWidth(1f);
            cell14.setBackgroundColor(myColor);
            //            PdfPTable nestedTable1 = new PdfPTable(2);
            //    nestedTable1.addCell(new Paragraph("Emp No."));
            //   nestedTable1.addCell(new Paragraph("379666"));

            //      cell41.addElement(nestedTable1);
            table2.addCell(cell11);
            table2.addCell(cell12);
            table2.addCell(cell13);
            table2.addCell(cell14);

            PdfPCell cell15 = new PdfPCell(new Paragraph("Emp ID.", font3));
            //cell15.setLeading(10f, 0f);
            cell15.setPadding(3);
            cell15.setBorderWidth(1f);
            cell15.setBackgroundColor(myColor1);
            PdfPCell cell16 = new PdfPCell(new Paragraph(rs.getString(1), font4));
            //  cell16.setLeading(10f, 0f);
            cell16.setPadding(3);
            cell16.setBorderWidth(1f);
            cell16.setBackgroundColor(myColor1);
            PdfPCell cell17 = new PdfPCell(new Paragraph("Bank Name", font3));
            //cell17.setLeading(10f, 0f);
            cell17.setPadding(3);
            cell17.setBorderWidth(1f);
            cell17.setBackgroundColor(myColor1);
            PdfPCell cell18 = new PdfPCell(new Paragraph(rs.getString(11), font4));
            //cell18.setLeading(10f, 0f);
            cell18.setPadding(3);
            cell18.setBorderWidth(1f);
            cell18.setBackgroundColor(myColor1);
            PdfPCell cell19 = new PdfPCell(new Paragraph("Location", font3));
            //cell19.setLeading(10f, 0f);
            cell19.setPadding(3);
            cell19.setBorderWidth(1f);
            cell19.setBackgroundColor(myColor1);
            PdfPCell cell20 = new PdfPCell(new Paragraph(rs.getString(13), font4));
            //cell20.setLeading(10f, 0f);
            cell20.setPadding(3);
            cell20.setBorderWidth(1f);
            cell20.setBackgroundColor(myColor1);

            table2.addCell(cell15);
            table2.addCell(cell16);
            table2.addCell(cell17);
            table2.addCell(cell18);
            table2.addCell(cell19);
            table2.addCell(cell20);

            PdfPCell cell21 = new PdfPCell(new Paragraph("Dsgn.", font3));
            //cell21.setLeading(10f, 0f);
            cell21.setPadding(3);
            cell21.setBorderWidth(1f);
            cell21.setBackgroundColor(myColor1);
            PdfPCell cell22 = new PdfPCell(new Paragraph(rs.getString(9), font4));
            //  cell22.setLeading(10f, 0f);
            cell22.setPadding(3);
            cell22.setBorderWidth(1f);
            cell22.setBackgroundColor(myColor1);
            PdfPCell cell23 = new PdfPCell(new Paragraph("Acc No.", font3));
            //cell23.setLeading(10f, 0f);
            cell23.setPadding(3);
            cell23.setBorderWidth(1f);
            cell23.setBackgroundColor(myColor1);

            int accno = Integer.parseInt(rs.getString(12));
            String accno1[] = new String[4];
            for (int i = 0; i < 4; i++) {
                accno1[i] = Integer.toString(accno % 10);
                accno /= 10;
            }

            PdfPCell cell24 = new PdfPCell(new Paragraph(
                    "XXXXXXX" + accno1[3] + "" + accno1[2] + "" + accno1[1] + "" + accno1[0], font4));
            //cell24.setLeading(10f, 0f);
            cell24.setPadding(3);
            cell24.setBorderWidth(1f);
            cell24.setBackgroundColor(myColor1);
            PdfPCell cell25 = new PdfPCell(new Paragraph("Base Br.", font3));
            //cell25.setLeading(10f, 0f);
            cell25.setPadding(3);
            cell25.setBorderWidth(1f);
            cell25.setBackgroundColor(myColor1);
            PdfPCell cell26 = new PdfPCell(new Paragraph("CC - Ahmedabad", font4));
            //cell26.setLeading(10f, 0f);
            cell26.setPadding(3);
            cell26.setBorderWidth(1f);
            cell26.setBackgroundColor(myColor1);

            table2.addCell(cell21);
            table2.addCell(cell22);
            table2.addCell(cell23);
            table2.addCell(cell24);
            table2.addCell(cell25);
            table2.addCell(cell26);

            PdfPCell cell27 = new PdfPCell(new Paragraph("Grade", font3));
            //cell27.setLeading(10f, 0f);
            cell27.setPadding(3);
            cell27.setBorderWidth(1f);
            cell27.setBackgroundColor(myColor1);
            PdfPCell cell28 = new PdfPCell(new Paragraph("C2", font4));
            //  cell28.setLeading(10f, 0f);
            cell28.setPadding(3);
            cell28.setBorderWidth(1f);
            cell28.setBackgroundColor(myColor1);
            PdfPCell cell29 = new PdfPCell(new Paragraph("Days paid", font3));
            //cell29.setLeading(10f, 0f);
            cell29.setPadding(3);
            cell29.setBorderWidth(1f);
            cell29.setBackgroundColor(myColor1);
            PdfPCell cell30 = new PdfPCell(new Paragraph(Integer.toString(rs1.getInt(5)), font4));
            //cell30.setLeading(10f, 0f);
            cell30.setPadding(3);
            cell30.setBorderWidth(1f);
            cell30.setBackgroundColor(myColor1);
            PdfPCell cell31 = new PdfPCell(new Paragraph("Depute Br.", font3));
            //cell31.setLeading(10f, 0f);
            cell31.setPadding(3);
            cell31.setBorderWidth(1f);
            cell31.setBackgroundColor(myColor1);
            PdfPCell cell32 = new PdfPCell(new Paragraph("CC - Ahmedabad", font4));
            //cell32.setLeading(10f, 0f);
            cell32.setPadding(3);
            cell32.setBorderWidth(1f);
            cell32.setBackgroundColor(myColor1);

            table2.addCell(cell27);
            table2.addCell(cell28);
            table2.addCell(cell29);
            table2.addCell(cell30);
            table2.addCell(cell31);
            table2.addCell(cell32);

            PdfPCell cell33 = new PdfPCell(new Paragraph("PAN", font3));
            //cell33.setLeading(10f, 0f);
            cell33.setPadding(3);
            cell33.setBorderWidth(1f);
            cell33.setBackgroundColor(myColor1);
            PdfPCell cell34 = new PdfPCell(new Paragraph("XXXXXXX792E", font4));
            //  cell34.setLeading(10f, 0f);
            cell34.setPadding(3);
            cell34.setBorderWidth(1f);
            cell34.setBackgroundColor(myColor1);
            PdfPCell cell35 = new PdfPCell(new Paragraph("Leave Balance", font3));
            //cell35.setLeading(10f, 0f);
            cell35.setPadding(3);
            cell35.setBorderWidth(1f);
            cell35.setBackgroundColor(myColor1);
            PdfPCell cell36 = new PdfPCell(new Paragraph(
                    "EL " + rs2.getInt(1) + "  SL " + rs2.getInt(2) + "  CL " + rs2.getInt(3), font4));
            // PdfPCell cell36 = new PdfPCell(new Paragraph("EL "+rs2.getInt(2),font4));
            //cell36.setLeading(10f, 0f);rs2.getInt(1)
            cell36.setPadding(3);
            cell36.setBorderWidth(1f);
            cell36.setBackgroundColor(myColor1);
            PdfPCell cell37 = new PdfPCell(new Paragraph(" WON/SWON", font3));
            //cell37.setLeading(10f, 0f);
            cell37.setPadding(3);
            cell37.setBorderWidth(1f);
            cell37.setBackgroundColor(myColor1);
            PdfPCell cell38 = new PdfPCell(new Paragraph("2616141", font4));
            //cell38.setLeading(10f, 0f);
            cell38.setPadding(3);
            cell38.setBorderWidth(1f);
            cell38.setBackgroundColor(myColor1);

            table2.addCell(cell33);
            table2.addCell(cell34);
            table2.addCell(cell35);
            table2.addCell(cell36);
            table2.addCell(cell37);
            table2.addCell(cell38);

            table2.setSpacingAfter(12f);

            document.add(table2);

            PdfPTable table3 = new PdfPTable(5); // 5 columns.
            table3.setWidthPercentage(100);

            PdfPCell cell39 = new PdfPCell(new Paragraph("Earnings", font1));
            cell39.setLeading(10f, 0f);
            cell39.setPadding(4);
            cell39.setBorderWidth(1f);
            cell39.setBackgroundColor(myColor);
            PdfPCell cell40 = new PdfPCell(new Paragraph("Arrears (INR)", font1));
            cell40.setLeading(10f, 0f);
            cell40.setPadding(4);
            cell40.setBorderWidth(1f);
            cell40.setBackgroundColor(myColor);
            PdfPCell cell41 = new PdfPCell(new Paragraph("Current (INR)", font1));
            cell41.setLeading(10f, 0f);
            cell41.setPadding(4);
            cell41.setBorderWidth(1f);
            cell41.setBackgroundColor(myColor);
            PdfPCell cell42 = new PdfPCell(new Paragraph("Deductions", font1));
            cell42.setLeading(10f, 0f);
            cell42.setPadding(4);
            cell42.setBorderWidth(1f);
            cell42.setBackgroundColor(myColor);
            PdfPCell cell43 = new PdfPCell(new Paragraph("Amount (INR)", font1));
            cell43.setLeading(10f, 0f);
            cell43.setPadding(4);
            cell43.setBorderWidth(1f);
            cell43.setBackgroundColor(myColor);

            table3.addCell(cell39);
            table3.addCell(cell40);
            table3.addCell(cell41);
            table3.addCell(cell42);
            table3.addCell(cell43);

            String[] sal = new String[10];
            sal[0] = "Basic Salary";
            sal[1] = "House Rent Allowance";
            sal[2] = "Medical Allowance";
            sal[3] = "Travelling Allowance";
            sal[4] = "Personal Allowance";
            sal[5] = "City Allowance";
            sal[6] = "Performance Pay";
            sal[7] = "Provident Fund";
            sal[8] = "Professional Tax";
            sal[9] = "Extra Leaves";

            Float[] val = new Float[10];
            val[0] = rs1.getFloat(4);
            val[1] = 6000.00f;
            val[2] = 1000.00f;
            val[3] = 1000.00f;
            val[4] = val[0] / 2;
            val[5] = 1000.00f;
            val[6] = val[4];
            val[7] = val[0] * 12 / 100;
            val[8] = 0.00f;
            if ((val[0] + val[4] + val[6]) * 12 > 250000.00f) {
                val[8] = (val[0] + val[4] + val[6]) / 10;
            }
            val[9] = 0.0f;
            if (rs2.getInt(1) < 0)
                val[9] -= (rs2.getInt(1) * val[0]) / 30;
            if (rs2.getInt(2) < 0)
                val[9] -= rs2.getInt(2) * val[0] / 30;
            if (rs2.getInt(3) < 0)
                val[9] -= rs2.getInt(3) * val[0] / 30;

            for (int i = 0; i < 7; i++) {
                PdfPCell cell44 = new PdfPCell(new Paragraph(sal[i], font3));
                //cell27.setLeading(10f, 0f);
                cell44.setPadding(3);
                cell44.setBorderWidth(1f);
                cell44.setBackgroundColor(myColor1);
                PdfPCell cell45 = new PdfPCell(new Paragraph("", font4));
                //  cell45.setLeading(10f, 0f);
                cell45.setPadding(3);
                cell45.setBorderWidth(1f);
                cell45.setBackgroundColor(myColor1);
                PdfPCell cell46 = new PdfPCell(new Paragraph(val[i].toString(), font3));
                //cell46.setLeading(10f, 0f);
                cell46.setHorizontalAlignment(Element.ALIGN_RIGHT);
                cell46.setPadding(3);
                cell46.setBorderWidth(1f);
                cell46.setBackgroundColor(myColor1);

                table3.addCell(cell44);
                table3.addCell(cell45);
                table3.addCell(cell46);

                if (i == 0 || i == 1 || i == 2) {
                    PdfPCell cell47 = new PdfPCell(new Paragraph(sal[7 + i], font4));
                    //cell47.setLeading(10f, 0f);
                    cell47.setPadding(3);
                    cell47.setBorderWidth(1f);
                    cell47.setBackgroundColor(myColor1);
                    table3.addCell(cell47);
                    PdfPCell cell48 = new PdfPCell(new Paragraph(val[i + 7].toString(), font3));
                    //cell48.setLeading(10f, 0f);
                    cell48.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    cell48.setPadding(3);
                    cell48.setBorderWidth(1f);
                    cell48.setBackgroundColor(myColor1);
                    table3.addCell(cell48);
                } else {
                    PdfPCell cell47 = new PdfPCell(new Paragraph("", font4));
                    cell47.setBorder(PdfPCell.NO_BORDER);
                    cell47.setBorderWidthRight(1f);
                    cell47.setColspan(2);
                    table3.addCell(cell47);
                }

            }

            PdfPCell cell48 = new PdfPCell(new Paragraph("", font4));
            //cell48.setBorder(PdfPCell.NO_BORDER);
            cell48.setColspan(3);
            table3.addCell(cell48);

            PdfPCell cell49 = new PdfPCell(new Paragraph("", font4));
            //cell49.setBorder(PdfPCell.NO_BORDER);
            cell49.setColspan(2);
            table3.addCell(cell49);
            table3.addCell(cell48);
            table3.addCell(cell49);
            table3.addCell(cell48);
            table3.addCell(cell49);
            table3.addCell(cell48);
            table3.addCell(cell49);

            PdfPCell cell50 = new PdfPCell(new Paragraph("Total Earnings (Current + Arrears)", font3));
            //cell27.setLeading(10f, 0f);
            cell50.setColspan(2);
            cell50.setPadding(3);
            cell50.setBorderWidth(1f);
            cell50.setBackgroundColor(myColor1);
            table3.addCell(cell50);

            float a = 0.0f;
            for (int i = 0; i < 7; i++) {
                a += val[i];
            }
            PdfPCell cell55 = new PdfPCell(new Paragraph(Float.toString(a), font3));
            //cell27.setLeading(10f, 0f);
            cell55.setPadding(3);
            cell55.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell55.setBorderWidth(1f);
            cell55.setBackgroundColor(myColor1);
            table3.addCell(cell55);

            PdfPCell cell51 = new PdfPCell(new Paragraph("Total Deductions", font3));
            //cell27.setLeading(10f, 0f);
            //cell51.setColspan(3);
            cell51.setPadding(3);
            cell51.setBorderWidth(1f);
            cell51.setBackgroundColor(myColor1);
            table3.addCell(cell51);

            float b = val[7] + val[8] + val[9];

            PdfPCell cell56 = new PdfPCell(new Paragraph(Float.toString(b), font3));
            //cell27.setLeading(10f, 0f);
            //cell56.setColspan(3);
            cell56.setPadding(3);
            cell56.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell56.setBorderWidth(1f);
            cell56.setBackgroundColor(myColor1);
            table3.addCell(cell56);

            table3.setSpacingAfter(12f);

            document.add(table3);

            PdfPTable table4 = new PdfPTable(5); // 2 columns.
            table4.setWidthPercentage(100);

            PdfPCell cell54 = new PdfPCell(new Paragraph("", font3));
            cell54.setBorder(PdfPCell.NO_BORDER);
            cell54.setColspan(3);
            table4.addCell(cell54);

            PdfPCell cell52 = new PdfPCell(new Paragraph("Net Pay", font5));
            cell52.setLeading(10f, 0f);
            // cell52.setBorder(PdfPCell.ALIGN_CENTER);
            cell52.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell52.setVerticalAlignment(Element.ALIGN_CENTER);

            cell52.setPadding(6f);
            cell52.setBorderWidth(1f);
            cell52.setBackgroundColor(myColor);
            table4.addCell(cell52);

            PdfPCell cell53 = new PdfPCell(new Paragraph("" + (a - b), font6));
            cell53.setLeading(10f, 0f);
            cell53.setPadding(6f);
            cell53.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell53.setVerticalAlignment(Element.ALIGN_CENTER);
            cell53.setBorderWidth(1f);

            table4.addCell(cell53);

            document.add(table4);

            // step 4
            // document.add(new Paragraph(String.format(
            //         "You have submitted the following text using the %s method:%s",
            //        request.getMethod(),uname)));
            //   document.add(new Paragraph(text));
            // step 5
            document.close();

            // setting some response headers
            response.setHeader("Expires", "0");
            response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
            response.setHeader("Pragma", "public");

            // the contentlength
            response.setContentLength(baos.size());
            // write ByteArrayOutputStream to the ServletOutputStream
            OutputStream os = response.getOutputStream();
            baos.writeTo(os);
            os.flush();
            os.close();
        } else {
            response.sendRedirect("index.jsp?id=Your session may be expired. You have to login first");

        }
    } catch (Exception e) {
        //       throw new IOException(e.getMessage());
        System.out.println(e);
        System.out.println("sssssssssssssssssss");

    }
}

From source file:FullPageTable.java

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document(PageSize.A4, 0, 0, 0, 0);
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();/*from  w w  w  .  j av  a 2  s.  co  m*/
    PdfPTable table = new PdfPTable(10);

    table.setWidthPercentage(100);
    table.setSpacingBefore(0f);
    table.setSpacingAfter(0f);

    // first row
    PdfPCell cell = new PdfPCell(new Phrase("DateRange"));
    cell.setColspan(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setPadding(10.0f);
    cell.setBackgroundColor(new BaseColor(140, 221, 8));
    table.addCell(cell);

    table.addCell("Calldate");
    table.addCell("Calltime");
    table.addCell("Source");
    table.addCell("DialedNo");
    table.addCell("Extension");
    table.addCell("Trunk");
    table.addCell("Duration");
    table.addCell("Calltype");
    table.addCell("Callcost");
    table.addCell("Site");

    for (int i = 0; i < 100; i++) {
        table.addCell("date" + i);
        table.addCell("time" + i);
        table.addCell("source" + i);
        table.addCell("destination" + i);
        table.addCell("extension" + i);
        table.addCell("trunk" + i);
        table.addCell("dur" + i);
        table.addCell("toc" + i);
        table.addCell("callcost" + i);
        table.addCell("Site" + i);
    }
    document.add(table);
    document.close();
}

From source file:generatereportbyaccz.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w  w w  . j  av a  2 s .  c  o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, ClassNotFoundException {
    // setting the content type
    response.setContentType("application/pdf");
    try {
        HttpSession session = request.getSession();
        if (session.getAttribute("username") != null) {
            // Get the text that will be added to the PDF

            String month = request.getParameter("month");
            String year = request.getParameter("year");
            //String id=request.getParameter("empid");
            //  System.out.println(id);
            //   String text = request.getParameter("text");
            //  if (text == null || text.trim().length() == 0) {
            //       text = "You didn't enter any text.";
            //  }
            //String id="Ultimate01";    
            Class.forName("com.mysql.jdbc.Driver").newInstance();

            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/payroll123", "root", "");

            PreparedStatement ps = con
                    .prepareStatement("SELECT SUM(basicsalary) as sum1 FROM payslip where month=? and year=?");
            ps.setString(1, month);
            ps.setString(2, year);
            System.out.println("hey1");
            PreparedStatement ps1 = con.prepareStatement(
                    "SELECT COUNT(DISTINCT employeeid) as emps FROM payslip where month=? and year=?");
            ps1.setString(1, month);
            ps1.setString(2, year);
            System.out.println("hey1");

            ResultSet rs = ps.executeQuery();
            //System.out.println(rs.getInt(1));

            rs.next();
            //             System.out.println(rs.getInt("sum1"));
            ResultSet rs1 = ps1.executeQuery();
            rs1.next();
            if (rs.getFloat("sum1") == 0.0 && rs1.getFloat("emps") == 0.0) {
                response.sendRedirect("generatereportbyaccz.jsp?id=Report of " + month + "/" + year
                        + " is not generated OR Record of this Report is not available in our Database");
            }
            // step 1
            Float[] val = new Float[9];
            val[0] = rs.getFloat("sum1");
            val[1] = 6000.00f * rs1.getFloat("emps");
            val[2] = 1000.00f * rs1.getFloat("emps");
            val[3] = 1000.00f * rs1.getFloat("emps");
            val[4] = val[0] / 2;
            val[5] = 1000.00f * rs1.getFloat("emps");
            val[6] = val[4];
            val[7] = val[0] * 12 / 100;
            val[8] = 0.00f;
            if ((val[0] + val[4] + val[6]) * 12 > 250000.00f) {
                val[8] = (val[0] + val[4] + val[6]) / 10;
            }

            //System.out.println("sssssssssssssssssss");

            Document document = new Document();
            // step 2
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PdfWriter.getInstance(document, baos);

            Font font0 = new Font(Font.FontFamily.TIMES_ROMAN, 11);
            Font font1 = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD);
            Font font2 = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD);
            Font font3 = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD);
            Font font4 = new Font(Font.FontFamily.HELVETICA, 10);
            Font font5 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD);
            Font font6 = new Font(Font.FontFamily.HELVETICA, 12);

            //font1.setColor(BaseColor.WHITE);
            BaseColor myColor = WebColors.getRGBColor("#F78181");
            BaseColor myColor1 = WebColors.getRGBColor("#FAFAFA");

            //step 3
            document.open();
            // step 3.5
            PdfPTable table1 = new PdfPTable(3); // 1 columns.
            // table1.setWidthPercentage(75);

            PdfPCell cell00 = new PdfPCell(new Paragraph("Monthly Payroll Summary\nFEB-2015", font2));
            cell00.setBorder(PdfPCell.NO_BORDER);
            cell00.setPaddingTop(18);
            cell00.setColspan(2);

            Image image = Image.getInstance("cc.jpg");
            PdfPCell cell0 = new PdfPCell(image, true);
            cell0.setBorder(PdfPCell.NO_BORDER);

            // cell0.setHorizontalAlignment(Element.ALIGN_RIGHT);
            //PdfPCell cell1 = new PdfPCell(new Paragraph("Mr. NILESH POPATBHAI LATHIYA"));
            table1.addCell(cell00);
            //          table1.addCell(cell0);
            table1.addCell(cell0);
            //  table1.addCell(cell1);
            //            table.addCell(cell2);
            //          table.addCell(cell3);
            table1.setWidthPercentage(100);
            table1.setSpacingAfter(8f);
            //table1.setSpacingBefore(20f);

            //table1.setSpacingAfter(10f);

            document.add(table1);
            //  table1.setWidthPercentage(100);
            PdfPTable table21 = new PdfPTable(2); // 3 columns.
            table21.setWidthPercentage(100);

            PdfPCell cell151 = new PdfPCell(new Paragraph("Total Number of Employees", font3));
            //cell15.setLeading(10f, 0f);
            cell151.setPadding(3);
            cell151.setBorderWidth(1f);
            cell151.setBackgroundColor(myColor1);

            PdfPCell cell161 = new PdfPCell(new Paragraph(Integer.toString(rs1.getInt("emps")), font4));
            //  cell16.setLeading(10f, 0f);
            cell161.setPadding(3);
            cell161.setBorderWidth(1f);
            cell161.setBackgroundColor(myColor1);

            table21.addCell(cell151);
            table21.addCell(cell161);

            table21.setSpacingAfter(12f);

            document.add(table21);

            PdfPTable table2 = new PdfPTable(2); // 3 columns.

            table2.setWidthPercentage(100);

            PdfPCell cell15 = new PdfPCell(new Paragraph("Total Basic Salary", font3));
            //cell15.setLeading(10f, 0f);
            cell15.setPadding(3);
            cell15.setBorderWidth(1f);
            cell15.setBackgroundColor(myColor1);

            PdfPCell cell16 = new PdfPCell(new Paragraph(Float.toString(val[0]), font4));
            //  cell16.setLeading(10f, 0f);
            cell16.setPadding(3);
            cell16.setBorderWidth(1f);
            cell16.setBackgroundColor(myColor1);

            PdfPCell cell17 = new PdfPCell(new Paragraph("Total House Rent Allowance", font3));
            //cell17.setLeading(10f, 0f);
            cell17.setPadding(3);
            cell17.setBorderWidth(1f);
            cell17.setBackgroundColor(myColor1);
            PdfPCell cell18 = new PdfPCell(new Paragraph(Float.toString(val[1]), font4));
            //cell18.setLeading(10f, 0f);
            cell18.setPadding(3);
            cell18.setBorderWidth(1f);
            cell18.setBackgroundColor(myColor1);
            PdfPCell cell19 = new PdfPCell(new Paragraph("Total Medical Allowance", font3));
            //cell19.setLeading(10f, 0f);
            cell19.setPadding(3);
            cell19.setBorderWidth(1f);
            cell19.setBackgroundColor(myColor1);
            PdfPCell cell20 = new PdfPCell(new Paragraph(Float.toString(val[2]), font4));
            //cell20.setLeading(10f, 0f);
            cell20.setPadding(3);
            cell20.setBorderWidth(1f);
            cell20.setBackgroundColor(myColor1);

            table2.addCell(cell15);
            table2.addCell(cell16);
            table2.addCell(cell17);
            table2.addCell(cell18);
            table2.addCell(cell19);
            table2.addCell(cell20);

            PdfPCell cell21 = new PdfPCell(new Paragraph("Total Travelling Allowance", font3));
            //cell21.setLeading(10f, 0f);
            cell21.setPadding(3);
            cell21.setBorderWidth(1f);
            cell21.setBackgroundColor(myColor1);
            PdfPCell cell22 = new PdfPCell(new Paragraph(Float.toString(val[3]), font4));
            //  cell22.setLeading(10f, 0f);
            cell22.setPadding(3);
            cell22.setBorderWidth(1f);
            cell22.setBackgroundColor(myColor1);
            PdfPCell cell23 = new PdfPCell(new Paragraph("Total Personal Allowance", font3));
            //cell23.setLeading(10f, 0f);
            cell23.setPadding(3);
            cell23.setBorderWidth(1f);
            cell23.setBackgroundColor(myColor1);

            PdfPCell cell24 = new PdfPCell(new Paragraph(Float.toString(val[4]), font4));
            //cell24.setLeading(10f, 0f);
            cell24.setPadding(3);
            cell24.setBorderWidth(1f);
            cell24.setBackgroundColor(myColor1);
            PdfPCell cell25 = new PdfPCell(new Paragraph("Total City Allowance", font3));
            //cell25.setLeading(10f, 0f);
            cell25.setPadding(3);
            cell25.setBorderWidth(1f);
            cell25.setBackgroundColor(myColor1);
            PdfPCell cell26 = new PdfPCell(new Paragraph(Float.toString(val[5]), font4));
            //cell26.setLeading(10f, 0f);
            cell26.setPadding(3);
            cell26.setBorderWidth(1f);
            cell26.setBackgroundColor(myColor1);

            table2.addCell(cell21);
            table2.addCell(cell22);
            table2.addCell(cell23);
            table2.addCell(cell24);
            table2.addCell(cell25);
            table2.addCell(cell26);

            PdfPCell cell27 = new PdfPCell(new Paragraph("Total Performance Pay", font3));
            //cell27.setLeading(10f, 0f);
            cell27.setPadding(3);
            cell27.setBorderWidth(1f);
            cell27.setBackgroundColor(myColor1);
            PdfPCell cell28 = new PdfPCell(new Paragraph(Float.toString(val[6]), font4));
            //  cell28.setLeading(10f, 0f);
            cell28.setPadding(3);
            cell28.setBorderWidth(1f);
            cell28.setBackgroundColor(myColor1);

            table2.addCell(cell27);
            table2.addCell(cell28);

            table2.setSpacingAfter(12f);

            document.add(table2);

            PdfPTable table3 = new PdfPTable(2); // 3 columns.
            table3.setWidthPercentage(100);

            PdfPCell cell271 = new PdfPCell(new Paragraph("Final Total amount paid by company", font3));
            //cell27.setLeading(10f, 0f);
            cell271.setPadding(3);
            cell271.setBorderWidth(1f);
            cell271.setBackgroundColor(myColor1);
            PdfPCell cell281 = new PdfPCell(new Paragraph(Float.toString(val[6]), font4));
            //  cell28.setLeading(10f, 0f);
            cell281.setPadding(3);
            cell281.setBorderWidth(1f);
            cell281.setBackgroundColor(myColor1);

            PdfPCell cell29 = new PdfPCell(new Paragraph("Total Provident Fund Collected", font3));
            //cell29.setLeading(10f, 0f);
            cell29.setPadding(3);
            cell29.setBorderWidth(1f);
            cell29.setBackgroundColor(myColor1);
            PdfPCell cell30 = new PdfPCell(new Paragraph(Float.toString(val[7]), font4));
            //cell30.setLeading(10f, 0f);
            cell30.setPadding(3);
            cell30.setBorderWidth(1f);
            cell30.setBackgroundColor(myColor1);
            PdfPCell cell31 = new PdfPCell(new Paragraph("Total Professional Tax Collected", font3));
            //cell31.setLeading(10f, 0f);
            cell31.setPadding(3);
            cell31.setBorderWidth(1f);
            cell31.setBackgroundColor(myColor1);
            PdfPCell cell32 = new PdfPCell(new Paragraph(Float.toString(val[8]), font4));
            //cell32.setLeading(10f, 0f);
            cell32.setPadding(3);
            cell32.setBorderWidth(1f);
            cell32.setBackgroundColor(myColor1);

            table3.addCell(cell271);
            table3.addCell(cell281);
            table3.addCell(cell29);
            table3.addCell(cell30);
            table3.addCell(cell31);
            table3.addCell(cell32);

            table3.setSpacingAfter(12f);

            document.add(table3);
            /*  PdfPCell cell33 = new PdfPCell(new Paragraph("PAN",font3));
              //cell33.setLeading(10f, 0f);
              cell33.setPadding(3);
              cell33.setBorderWidth(1f);
              cell33.setBackgroundColor(myColor1);
              PdfPCell cell34 = new PdfPCell(new Paragraph("XXXXXXX792E",font4));
            //  cell34.setLeading(10f, 0f);
              cell34.setPadding(3);
              cell34.setBorderWidth(1f);
              cell34.setBackgroundColor(myColor1);
              PdfPCell cell35 = new PdfPCell(new Paragraph("Leave Balance",font3));
              //cell35.setLeading(10f, 0f);
              cell35.setPadding(3);
              cell35.setBorderWidth(1f);
              cell35.setBackgroundColor(myColor1);
              PdfPCell cell36 = new PdfPCell(new Paragraph("EL X SL X CL X",font4));
              //cell36.setLeading(10f, 0f);
              cell36.setPadding(3);
              cell36.setBorderWidth(1f);
              cell36.setBackgroundColor(myColor1);
              PdfPCell cell37 = new PdfPCell(new Paragraph(" WON/SWON",font3));
              //cell37.setLeading(10f, 0f);
              cell37.setPadding(3);
              cell37.setBorderWidth(1f);
              cell37.setBackgroundColor(myColor1);
              PdfPCell cell38 = new PdfPCell(new Paragraph("2616141",font4));
              //cell38.setLeading(10f, 0f);
              cell38.setPadding(3);
              cell38.setBorderWidth(1f);
              cell38.setBackgroundColor(myColor1);
                      
              table2.addCell(cell33);
              table2.addCell(cell34);
              table2.addCell(cell35);
              table2.addCell(cell36);
              table2.addCell(cell37);
              table2.addCell(cell38);
             */

            /* 
             PdfPTable table3 = new PdfPTable(5); // 5 columns.
             table3.setWidthPercentage(100);
                    
             PdfPCell cell39 = new PdfPCell(new Paragraph("Earnings",font1));
             cell39.setLeading(10f, 0f);
             cell39.setPadding(4);
             cell39.setBorderWidth(1f);
             cell39.setBackgroundColor(myColor);
             PdfPCell cell40 = new PdfPCell(new Paragraph("Arrears (INR)",font1));
             cell40.setLeading(10f, 0f);
             cell40.setPadding(4);
             cell40.setBorderWidth(1f);
             cell40.setBackgroundColor(myColor);
             PdfPCell cell41 = new PdfPCell(new Paragraph("Current (INR)",font1));
             cell41.setLeading(10f, 0f);
             cell41.setPadding(4);
             cell41.setBorderWidth(1f);
             cell41.setBackgroundColor(myColor);
             PdfPCell cell42 = new PdfPCell(new Paragraph("Deductions",font1));
             cell42.setLeading(10f, 0f);
             cell42.setPadding(4);
             cell42.setBorderWidth(1f);
             cell42.setBackgroundColor(myColor);
             PdfPCell cell43 = new PdfPCell(new Paragraph("Amount (INR)",font1));
             cell43.setLeading(10f, 0f);
             cell43.setPadding(4);
             cell43.setBorderWidth(1f);
             cell43.setBackgroundColor(myColor);
                     
             table3.addCell(cell39);
             table3.addCell(cell40);
             table3.addCell(cell41);
             table3.addCell(cell42);
             table3.addCell(cell43);
                     
             String[] sal = new String[9];
             sal[0]="Basic Salary";
             sal[1]="House Rent Allowance";
             sal[2]="Medical Allowance";
             sal[3]="Travelling Allowance";
             sal[4]="Personal Allowance";
             sal[5]="City Allowance";
             sal[6]="Performance Pay";
             sal[7]="Provident Fund";
             sal[8]="Professional Tax";
                     
             Float[] val = new Float[9];
             val[0]=rs1.getFloat(4);
             val[1]=6000.00f;
             val[2]=1000.00f;
             val[3]=1000.00f;
             val[4]=val[0]/2;
             val[5]=1000.00f;
             val[6]=val[4];
             val[7]=val[0]*12/100;
             val[8]=0.00f;
             if((val[0]+val[4]+val[6])*12>250000.00f)
             {
                 val[8]=(val[0]+val[4]+val[6])/10;
             }
                     
                     
                     
             for(int i=0;i<7;i++)
             {
              PdfPCell cell44 = new PdfPCell(new Paragraph(sal[i],font3));
             //cell27.setLeading(10f, 0f);
             cell44.setPadding(3);
             cell44.setBorderWidth(1f);
             cell44.setBackgroundColor(myColor1);
             PdfPCell cell45 = new PdfPCell(new Paragraph("",font4));
            //  cell45.setLeading(10f, 0f);
             cell45.setPadding(3);
             cell45.setBorderWidth(1f);
             cell45.setBackgroundColor(myColor1);
             PdfPCell cell46 = new PdfPCell(new Paragraph(val[i].toString(),font3));
             //cell46.setLeading(10f, 0f);
             cell46.setHorizontalAlignment(Element.ALIGN_RIGHT);
             cell46.setPadding(3);
             cell46.setBorderWidth(1f);
             cell46.setBackgroundColor(myColor1);
                         
             table3.addCell(cell44);
             table3.addCell(cell45);
             table3.addCell(cell46);
                     
                     
             if(i==0 || i==1) {       
             PdfPCell cell47 = new PdfPCell(new Paragraph(sal[7+i],font4));
             //cell47.setLeading(10f, 0f);
             cell47.setPadding(3);
             cell47.setBorderWidth(1f);
             cell47.setBackgroundColor(myColor1);
             table3.addCell(cell47);
             PdfPCell cell48 = new PdfPCell(new Paragraph(val[i+7].toString(),font3));
             //cell48.setLeading(10f, 0f);
             cell48.setHorizontalAlignment(Element.ALIGN_RIGHT);
             cell48.setPadding(3);
             cell48.setBorderWidth(1f);
             cell48.setBackgroundColor(myColor1);
             table3.addCell(cell48);
             }
             else
             {
             PdfPCell cell47 = new PdfPCell(new Paragraph("",font4));
             cell47.setBorder(PdfPCell.NO_BORDER);
             cell47.setBorderWidthRight (1f);
             cell47.setColspan(2);
             table3.addCell(cell47);
             }
                        
             }
                     
             PdfPCell cell48 = new PdfPCell(new Paragraph("",font4));
             //cell48.setBorder(PdfPCell.NO_BORDER);
             cell48.setColspan(3);
             table3.addCell(cell48);
                     
             PdfPCell cell49 = new PdfPCell(new Paragraph("",font4));
             //cell49.setBorder(PdfPCell.NO_BORDER);
             cell49.setColspan(2);
             table3.addCell(cell49);
             table3.addCell(cell48);
             table3.addCell(cell49);
             table3.addCell(cell48);
             table3.addCell(cell49);
             table3.addCell(cell48);
             table3.addCell(cell49);
                    
                     
             PdfPCell cell50 = new PdfPCell(new Paragraph("Total Earnings (Current + Arrears)",font3));
             //cell27.setLeading(10f, 0f);
             cell50.setColspan(2);
             cell50.setPadding(3);
             cell50.setBorderWidth(1f);
             cell50.setBackgroundColor(myColor1);
             table3.addCell(cell50);
                     
             float a = 0.0f;
            for(int i=0;i<7;i++)
            {a+=val[i];}
             PdfPCell cell55 = new PdfPCell(new Paragraph(Float.toString(a),font3));
             //cell27.setLeading(10f, 0f);
             cell55.setPadding(3);
             cell55.setHorizontalAlignment(Element.ALIGN_RIGHT);
             cell55.setBorderWidth(1f);
             cell55.setBackgroundColor(myColor1);
             table3.addCell(cell55);
                     
                     
             PdfPCell cell51 = new PdfPCell(new Paragraph("Total Deductions",font3));
             //cell27.setLeading(10f, 0f);
             //cell51.setColspan(3);
             cell51.setPadding(3);
             cell51.setBorderWidth(1f);
             cell51.setBackgroundColor(myColor1);
             table3.addCell(cell51);
                     
             float b = val[7]+val[8];
                    
             PdfPCell cell56 = new PdfPCell(new Paragraph(Float.toString(b),font3));
             //cell27.setLeading(10f, 0f);
             //cell56.setColspan(3);
             cell56.setPadding(3);
             cell56.setHorizontalAlignment(Element.ALIGN_RIGHT);
             cell56.setBorderWidth(1f);
             cell56.setBackgroundColor(myColor1);
             table3.addCell(cell56);
                     
             table3.setSpacingAfter(12f);
                    
             document.add(table3);
                    
             PdfPTable table4 = new PdfPTable(5); // 2 columns.
             table4.setWidthPercentage(100);
                     
             PdfPCell cell54 = new PdfPCell(new Paragraph("",font3));
             cell54.setBorder(PdfPCell.NO_BORDER);
             cell54.setColspan(3);
             table4.addCell(cell54);
                     
             PdfPCell cell52 = new PdfPCell(new Paragraph("Net Pay",font5));
            cell52.setLeading(10f, 0f);
            // cell52.setBorder(PdfPCell.ALIGN_CENTER);
             cell52.setHorizontalAlignment(Element.ALIGN_LEFT);
             cell52.setVerticalAlignment(Element.ALIGN_CENTER);
                     
             cell52.setPadding(6f);
             cell52.setBorderWidth(1f);
             cell52.setBackgroundColor(myColor);
             table4.addCell(cell52);
                     
             PdfPCell cell53 = new PdfPCell(new Paragraph(""+(a-b),font6));
             cell53.setLeading(10f, 0f);
             cell53.setPadding(6f);
                  cell53.setHorizontalAlignment(Element.ALIGN_CENTER);
             cell53.setVerticalAlignment(Element.ALIGN_CENTER);
            cell53.setBorderWidth(1f);
                     
             table4.addCell(cell53);
                     
             document.add(table4);
                    
            */

            // step 4
            // document.add(new Paragraph(String.format(
            //         "You have submitted the following text using the %s method:%s",
            //        request.getMethod(),uname)));
            //   document.add(new Paragraph(text));
            // step 5
            document.close();

            // setting some response headers
            response.setHeader("Expires", "0");
            response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
            response.setHeader("Pragma", "public");

            // the contentlength
            response.setContentLength(baos.size());
            // write ByteArrayOutputStream to the ServletOutputStream
            OutputStream os = response.getOutputStream();
            baos.writeTo(os);
            os.flush();
            os.close();
        } else {
            response.sendRedirect("index.jsp?id=Your session may be expired. You have to login first");

        }
    } catch (Exception e) {
        //       throw new IOException(e.getMessage());
        System.out.println(e);
        System.out.println("sssssssssssssssssss");

    }
}

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 {/*  w ww.j ava  2  s . c om*/

        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.kcbj.placemat.Placemat.java

License:Open Source License

private void createPdf(File file, List<Sponsor> sponsors) throws IOException, DocumentException {
    System.out.println("Generating PDF file " + file.getAbsolutePath());
    Layout layout = new Layout(sponsors);
    System.out.println("Layout = " + layout);

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(file));
    document.setPageSize(PageSize.A4.rotate());
    document.setMargins(PADDING_DOC, PADDING_DOC, PADDING_DOC, PADDING_DOC);
    document.open();/*from ww  w .j  a v a 2 s .c  o m*/

    PdfPTable table = new PdfPTable(layout.getColumnCount());
    table.setWidthPercentage(100);
    table.setSpacingBefore(0f);
    table.setSpacingAfter(0f);
    for (int i = 0; i < sponsors.size(); i++) {
        table.addCell(generateCell(sponsors.get(i), layout.getCellHeight()));
    }
    for (int i = 0; i < layout.getEmptyCellCount(); i++) {
        table.addCell(generateCell(new Sponsor(), layout.getCellHeight()));
    }
    document.add(table);

    document.close();
}

From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java

private void addDisciplinaryRecordDetails(PdfPTable table, DisciplinaryRecord disRec) {
    if (disRec.followUp.length() > 0) {
        PdfPTable detailsTable = new PdfPTable(10);
        detailsTable.setWidthPercentage(100);

        // follow-up in grey and italic
        //detailsTable.addCell(createValueCell(disRec.followUp.replaceAll("\r\n"," "),10));
        Font font = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.ITALIC);
        font.setColor(BaseColor.GRAY);// www.  ja v  a 2 s.  c  o  m
        cell = new PdfPCell(new Paragraph(disRec.followUp.replaceAll("\r\n", " "), font));
        cell.setColspan(10);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(innerBorderColor);
        cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        detailsTable.addCell(cell);

        table.addCell(createCell(new PdfPCell(detailsTable), table.getNumberOfColumns(), PdfPCell.ALIGN_CENTER,
                PdfPCell.BOX));
    }
}

From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java

private void addLeaveDetails(PdfPTable table, Leave leave) {
    if (leave.comment.length() > 0) {
        PdfPTable detailsTable = new PdfPTable(10);
        detailsTable.setWidthPercentage(100);

        // follow-up in grey and italic
        //detailsTable.addCell(createValueCell(leave.comment.replaceAll("\r\n"," "),10));
        Font font = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.ITALIC);
        font.setColor(BaseColor.GRAY);//from ww w.j  av  a 2s  .co  m
        cell = new PdfPCell(new Paragraph(leave.comment.replaceAll("\r\n", " "), font));
        cell.setColspan(10);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(innerBorderColor);
        cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        detailsTable.addCell(cell);

        table.addCell(createCell(new PdfPCell(detailsTable), table.getNumberOfColumns(), PdfPCell.ALIGN_CENTER,
                PdfPCell.BOX));
    }
}

From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java

private void addContractDetails(PdfPTable table, Contract contract) {
    PdfPTable detailsTable = new PdfPTable(10);
    detailsTable.setWidthPercentage(100);

    if (contract.getLegalReferenceCode(1).length() > 0 || contract.getLegalReferenceCode(2).length() > 0
            || contract.getLegalReferenceCode(3).length() > 0 || contract.getLegalReferenceCode(4).length() > 0
            || contract.getLegalReferenceCode(5).length() > 0) {
        //detailsTable.addCell(createSubtitleCell(getTran("web.hr","legalReferenceCodes"),10));

        // one LRC
        for (int i = 0; i < 4; i++) {
            if (contract.getLegalReferenceCode(i + 1).length() > 0) {
                detailsTable//w  w  w. j  a  v a2  s .c  om
                        .addCell(createValueCell(getTran("web.hr", "legalReferenceCode") + " " + (i + 1), 4));
                detailsTable.addCell(createValueCell(contract.getLegalReferenceCode(i + 1), 6));
            }
        }
    }

    if (detailsTable.size() > 0) {
        table.addCell(emptyCell(2));
        cell = createCell(new PdfPCell(detailsTable), table.getNumberOfColumns() - 2, PdfPCell.ALIGN_CENTER,
                PdfPCell.BOX);
        cell.setPadding(2);
        table.addCell(cell);
    }
}

From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java

private void addCareerDetails(PdfPTable table, Career career) {
    if (career.comment.length() > 0) {
        PdfPTable detailsTable = new PdfPTable(10);
        detailsTable.setWidthPercentage(100);

        // comment in grey and italic
        //detailsTable.addCell(createValueCell(career.comment.replaceAll("\r\n"," "),10));
        Font font = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.ITALIC);
        font.setColor(BaseColor.GRAY);/*from  ww w  .  j  av  a  2  s  . co  m*/
        cell = new PdfPCell(new Paragraph(career.comment.replaceAll("\r\n", " "), font));
        cell.setColspan(10);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(innerBorderColor);
        cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        detailsTable.addCell(cell);

        table.addCell(createCell(new PdfPCell(detailsTable), table.getNumberOfColumns(), PdfPCell.ALIGN_CENTER,
                PdfPCell.BOX));
    }
}