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

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

Introduction

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

Prototype

public void setLeading(float fixedLeading, float multipliedLeading) 

Source Link

Document

Sets the leading fixed and variable.

Usage

From source file:generatepayslipbyaccz.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// ww w  . ja  v  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 = 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   w  ww.  j  a  v  a  2s  .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:com.asae.controllers.BeanGestionRutinas.java

public void generarPdf() {
    Document document = new Document();
    try {//from   ww w  .j  a v  a2  s .co m
        File file = File.createTempFile("rutina-", ".pdf", new File("/var/webapp/pdf"));
        pdfFileName = file.getName();

        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        Font bold = new Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD);
        URL url = FacesContext.getCurrentInstance().getExternalContext()
                .getResource("/resources/img/logo-unicauca-negro.png");
        Image imgLogoUnicauca = Image.getInstance(url);
        imgLogoUnicauca.scaleAbsolute(118f, 131f);

        PdfPTable tableEncabezado = new PdfPTable(2);
        tableEncabezado.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableEncabezado.setWidthPercentage(100);
        tableEncabezado.setSpacingAfter(5);
        PdfPCell cell1 = new PdfPCell(imgLogoUnicauca);
        cell1.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell2 = new PdfPCell(new Paragraph("Vicerrectoria Administrativa"));
        cell2.setBorder(Rectangle.NO_BORDER);
        cell2.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        PdfPCell cell3 = new PdfPCell(new Paragraph("Universidad del Cauca", bold));
        cell3.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell4 = new PdfPCell(new Paragraph("Gimnasio y Actividad Fsica", bold));
        cell4.setBorder(Rectangle.NO_BORDER);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        tableEncabezado.addCell(cell1);
        tableEncabezado.addCell(cell2);
        tableEncabezado.addCell(cell3);
        tableEncabezado.addCell(cell4);

        PdfPTable tableDatosUsuario = new PdfPTable(3);
        tableDatosUsuario.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableDatosUsuario.setWidthPercentage(100);
        tableDatosUsuario.setSpacingBefore(20);
        PdfPCell cell5 = new PdfPCell(new Paragraph("Nombre: " + rutinaVisualizar.getIdusuario().getFisrtname()
                + " " + rutinaVisualizar.getIdusuario().getSecondname() + " "
                + rutinaVisualizar.getIdusuario().getFirstlastname() + " "
                + rutinaVisualizar.getIdusuario().getSecondlastname()));
        cell5.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell6 = new PdfPCell();
        cell6.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell7 = new PdfPCell();
        cell7.setBorder(Rectangle.NO_BORDER);

        tableDatosUsuario.addCell(cell5);
        tableDatosUsuario.addCell(cell6);
        tableDatosUsuario.addCell(cell7);

        PdfPTable tableFechas = new PdfPTable(3);
        tableFechas.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableFechas.setWidthPercentage(100);
        tableFechas.setSpacingBefore(10);
        PdfPCell cell8 = new PdfPCell(
                new Paragraph("Fecha de inicio: " + getMyFormattedDate(rutinaVisualizar.getFechaInicio())));
        cell8.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell9 = new PdfPCell(
                new Paragraph("Fecha de fin: " + getMyFormattedDate(rutinaVisualizar.getFechaFin())));
        cell9.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell10 = new PdfPCell();
        cell10.setBorder(Rectangle.NO_BORDER);

        tableFechas.addCell(cell8);
        tableFechas.addCell(cell9);
        tableFechas.addCell(cell10);

        PdfPTable tableMedidas = new PdfPTable(4);
        tableMedidas.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableMedidas.setWidthPercentage(100);
        tableMedidas.setSpacingBefore(10);

        Usuario usuAux = rutinaVisualizar.getIdusuario();
        List<Evaluacion> lstEvalAux = usuAux.getEvaluacionList();
        Evaluacion evalAux;
        double peso = 0;
        if (lstEvalAux.size() > 0) {
            evalAux = lstEvalAux.get(lstEvalAux.size() - 1);
            peso = evalAux.getPeso().doubleValue();
        }

        double estatura = 0;
        MedidasGenerales medGenAux = usuAux.getMedidasGenerales();
        if (medGenAux != null) {
            estatura = medGenAux.getEstatura().doubleValue();
        }

        PdfPCell cell11 = new PdfPCell(new Paragraph("Peso: " + peso));
        cell11.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell12 = new PdfPCell(new Paragraph("Talla: " + estatura));
        cell12.setBorder(Rectangle.NO_BORDER);

        double imc = 0;
        if (peso != 0 && estatura != 0) {
            imc = peso / Math.pow(estatura, 2);
        }

        PdfPCell cell13 = new PdfPCell(new Paragraph("I.M.C: " + imc));
        cell13.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell14 = new PdfPCell(new Paragraph("Rutina: " + rutinaVisualizar.getCodigoRutina()));
        cell14.setBorder(Rectangle.NO_BORDER);

        tableMedidas.addCell(cell11);
        tableMedidas.addCell(cell12);
        tableMedidas.addCell(cell13);
        tableMedidas.addCell(cell14);

        PdfPTable tableDias = new PdfPTable(2);
        tableDias.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableDias.setWidthPercentage(100);
        tableDias.setSpacingBefore(20);
        tableDias.setHorizontalAlignment(Element.ALIGN_LEFT);
        tableDias.setWidths(new int[] { 1, 9 });

        List<Dia> lstDiasPDF = rutinaVisualizar.getDiaList();

        PdfPCell cellCabezeraDia = new PdfPCell(new Paragraph("Da", bold));
        PdfPCell cellCabezeraDia2 = new PdfPCell();
        cellCabezeraDia2.setBorder(Rectangle.NO_BORDER);

        tableDias.addCell(cellCabezeraDia);
        tableDias.addCell(cellCabezeraDia2);

        for (Dia dia : lstDiasPDF) {
            PdfPCell cellDia = new PdfPCell(new Paragraph(dia.getNumDia().toString()));
            PdfPCell cellDia2 = new PdfPCell();
            cellDia2.setBorder(Rectangle.NO_BORDER);

            List<GrupoMuscular> lstGMuscularPDF = dia.getGrupoMuscularList();

            if (lstGMuscularPDF.size() > 0) {
                PdfPTable tableGMuscular = new PdfPTable(2);
                tableGMuscular.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                tableGMuscular.setWidthPercentage(100);
                tableGMuscular.setHorizontalAlignment(Element.ALIGN_LEFT);
                tableGMuscular.setWidths(new int[] { 1, 6 });

                PdfPCell cellCabezeraGMuscular = new PdfPCell(new Paragraph("Grupo Muscular", bold));
                cellCabezeraGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                PdfPCell cellCabezeraGMuscular2 = new PdfPCell();
                cellCabezeraGMuscular2.setBorder(Rectangle.NO_BORDER);
                tableGMuscular.addCell(cellCabezeraGMuscular);
                tableGMuscular.addCell(cellCabezeraGMuscular2);

                int aux = 1;
                for (GrupoMuscular gMuscularFor : lstGMuscularPDF) {
                    PdfPCell cellGMuscular = new PdfPCell(
                            new Paragraph(gMuscularFor.getIdgrupoMuscularGeneral().getNombre()));
                    cellGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                    PdfPCell cellGMuscular2 = new PdfPCell();
                    cellGMuscular2.setBorder(Rectangle.NO_BORDER);

                    List<EjercicioGm> lstEjerciciosGMuscularPDF = gMuscularFor.getEjercicioGmList();
                    BaseColor myColor = WebColors.getRGBColor("#CCEEFF");
                    if (lstEjerciciosGMuscularPDF.size() > 0) {
                        PdfPTable tableEjercicioGMsucular = new PdfPTable(5);
                        tableEjercicioGMsucular.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                        tableEjercicioGMsucular.setWidthPercentage(100);
                        tableEjercicioGMsucular.setHorizontalAlignment(Element.ALIGN_LEFT);

                        PdfPCell cellCabezeraEjercicioGM = new PdfPCell(new Paragraph("Ejercicio", bold));
                        cellCabezeraEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM);

                        PdfPCell cellCabezeraEjercicioGM2 = new PdfPCell(new Paragraph("Series", bold));
                        cellCabezeraEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM2.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM2.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM2);

                        PdfPCell cellCabezeraEjercicioGM3 = new PdfPCell(new Paragraph("Repeticiones", bold));
                        cellCabezeraEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM3.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM3.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM3);

                        PdfPCell cellCabezeraEjercicioGM4 = new PdfPCell(new Paragraph("Receso", bold));
                        cellCabezeraEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM4.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM4.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM4);

                        PdfPCell cellCabezeraEjercicioGM5 = new PdfPCell(new Paragraph("Peso", bold));
                        cellCabezeraEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM5.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM5.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM5);

                        int aux2 = 1;
                        for (EjercicioGm ejercicioGm : lstEjerciciosGMuscularPDF) {
                            PdfPCell cellEjercicioGM = new PdfPCell(
                                    new Paragraph(ejercicioGm.getEjercicio().getNombre()));
                            cellEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM.setLeading(20f, 0f);

                            PdfPCell cellEjercicioGM2 = new PdfPCell(
                                    new Paragraph(ejercicioGm.getNumeroSeries().toString()));
                            cellEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM2.setLeading(20f, 0f);

                            PdfPCell cellEjercicioGM3 = new PdfPCell(
                                    new Paragraph(ejercicioGm.getRepeticiones().toString()));
                            cellEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM3.setLeading(20f, 0f);

                            PdfPCell cellEjercicioGM4 = new PdfPCell(
                                    new Paragraph(ejercicioGm.getReceso().toString()));
                            cellEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM4.setLeading(20f, 0f);

                            PdfPCell cellEjercicioGM5 = new PdfPCell(
                                    new Paragraph(ejercicioGm.getPeso().toString()));
                            cellEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM5.setLeading(20f, 0f);

                            if (aux2 % 2 == 0) {
                                cellEjercicioGM.setBackgroundColor(myColor);
                                cellEjercicioGM2.setBackgroundColor(myColor);
                                cellEjercicioGM3.setBackgroundColor(myColor);
                                cellEjercicioGM4.setBackgroundColor(myColor);
                                cellEjercicioGM5.setBackgroundColor(myColor);
                            }

                            tableEjercicioGMsucular.addCell(cellEjercicioGM);
                            tableEjercicioGMsucular.addCell(cellEjercicioGM2);
                            tableEjercicioGMsucular.addCell(cellEjercicioGM3);
                            tableEjercicioGMsucular.addCell(cellEjercicioGM4);
                            tableEjercicioGMsucular.addCell(cellEjercicioGM5);
                            aux2++;
                        }
                        cellGMuscular2.addElement(tableEjercicioGMsucular);
                    }
                    tableGMuscular.addCell(cellGMuscular);
                    tableGMuscular.addCell(cellGMuscular2);
                    aux++;
                }
                cellDia2.addElement(tableGMuscular);
            }
            tableDias.addCell(cellDia);
            tableDias.addCell(cellDia2);
        }

        LineSeparator ls = new LineSeparator();
        document.add(tableEncabezado);
        document.add(ls);
        document.add(tableDatosUsuario);
        document.add(tableFechas);
        document.add(tableMedidas);
        document.add(tableDias);
        document.close();
    } catch (DocumentException | FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException ex) {
        Logger.getLogger(BeanGestionRutinas.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java

private void createTable(Document document) throws DocumentException, MalformedURLException, IOException {

    PdfPTable table = new PdfPTable(8);
    table.setWidths(new int[] { 5, 10, 30, 15, 15, 15, 25, 20 });
    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    //       addLogo(table);
    String[] headerTitle = { "Sl", "Qty", "Medicine Name", "Mfg Date", "Batch", "Exp Date", "Schedule",
            "Price" };
    Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.BOLD);
    for (String header : headerTitle) {
        Phrase p = new Phrase(header, headerFont);
        PdfPCell c1 = new PdfPCell(p);
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setLeading(0f, 1.5f);
        c1.setBackgroundColor(BaseColor.GRAY);
        table.addCell(c1);/*www .  j  ava2 s  .c o  m*/
    }

    Font contentFont = new Font(Font.FontFamily.TIMES_ROMAN, 9f);
    MedicineUtility mUtil = new MedicineUtility();
    //       table.setSpacingAfter(20);
    double vat = 0.0;
    double discount = 0.0;
    int count = 1;
    double totalAmt = 0.0;
    if (totalRecords != null && totalRecords.size() > 0) {
        for (InvoiceBean iBean : totalRecords) {
            //              replaceDoctor = iBean.getDoctorName();
            //              replaceCustomer = iBean.getCustomerName();
            //              replaceCustAddr1 = iBean.getCustomerAddr1();
            //              replaceBillNo = iBean.getBillNo();
            //              replaceBillDate = iBean.getPurchaseDate();
            vat = iBean.getVat();
            discount = iBean.getDiscount();
            PdfPCell c = new PdfPCell(new Phrase(count++ + "", contentFont));
            table.addCell(c);
            c = new PdfPCell(new Phrase(iBean.getSoldoutStock() + "", contentFont));
            table.addCell(c);
            table.addCell(new PdfPCell(new Phrase(iBean.getMedicineName(), contentFont)));
            table.addCell(new PdfPCell(new Phrase(iBean.getMfgDate(), contentFont)));
            table.addCell(new PdfPCell(new Phrase(iBean.getBatchName(), contentFont)));
            table.addCell(new PdfPCell(new Phrase(iBean.getExpDate(), contentFont)));
            table.addCell(new PdfPCell(new Phrase(iBean.getSchedule(), contentFont)));
            totalAmt = totalAmt + (iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice());
            table.addCell(new PdfPCell(new Phrase(
                    mUtil.getFormattedAmount((iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice())),
                    contentFont)));
        }
    }
    double grandTotal = 0.0;

    // Total
    PdfPCell c1 = new PdfPCell(new Phrase("Total"));
    c1.setColspan(7);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(totalAmt)));
    c1.setColspan(1);
    table.addCell(c1);

    // Vat
    c1 = new PdfPCell(new Phrase("Vat(" + vat + "%)"));
    c1.setColspan(7);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    double vatAmt = totalAmt * vat / 100;
    c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(vatAmt)));
    c1.setColspan(1);
    table.addCell(c1);

    // Discount
    c1 = new PdfPCell(new Phrase("Discount(" + discount + "%)"));
    c1.setColspan(7);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    double discountAmt = totalAmt * discount / 100;
    c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(discountAmt)));
    c1.setColspan(1);
    table.addCell(c1);

    // Grand Total
    c1 = new PdfPCell(new Phrase("Grand Total"));
    c1.setColspan(7);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    grandTotal = (totalAmt + vatAmt - discountAmt);
    c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(grandTotal)));
    c1.setColspan(1);
    table.addCell(c1);

    document.add(table);
}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * /*from  w w  w .  j  a v a2 s  .c om*/
 *  box 
 *
 * @param section box  section ?
 * @param e box   element
 * @throws Exception
 */
public static void setBox(Section section, Element e) throws Exception {

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(1);
    t.setSpacingAfter(12);

    if (e.getAttributeValue("width") != null)
        t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width")));

    PdfPCell cell = new PdfPCell();
    if (e.getAttributeValue("option") != null) {

        ColumnText col = new ColumnText(null);
        for (Element e1 : e.getChildren()) {
            if (e1.getAttributeValue("type").equals("red"))
                col.addText(new Phrase(e1.getText(), fnBoxRed));
            else
                col.addText(new Phrase(e1.getText(), fnBox));
        }
        cell.setColumn(col);

    } else {
        cell.setPhrase(new Phrase(e.getText(), fnBox));
    }

    cell.setPaddingLeft(10);
    cell.setLeading(0.0F, 1.8F);
    cell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(new BaseColor(238, 236, 225));

    t.addCell(cell);

    section.add(t);

}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * //from   w  w w  .j  a  v  a 2 s .  c o m
 * box (Backgroud : Black)
 *
 * @param section box  section ?
 * @param e box   element
 * @throws Exception
 */
public static void setBoxB(Section section, Element e) throws Exception {

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(1);
    t.setSpacingAfter(12);

    if (e.getAttributeValue("width") != null)
        t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width")));

    PdfPCell cell = new PdfPCell();
    if (e.getAttributeValue("option") != null) {

        ColumnText col = new ColumnText(null);
        for (Element e1 : e.getChildren()) {
            if (e1.getAttributeValue("type").equals("red"))
                col.addText(new Phrase(e1.getText(), fnBoxRed));
            else
                col.addText(new Phrase(e1.getText(), fnBoxWhite));
        }
        cell.setColumn(col);

    } else {
        cell.setPhrase(new Phrase(e.getText(), fnBoxWhite));
    }

    cell.setPaddingLeft(10);
    cell.setLeading(0.0F, 1.8F);
    cell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(new BaseColor(0, 0, 0));

    t.addCell(cell);

    section.add(t);

}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * /*from w ww  .j a  v  a  2s.  c o m*/
 * box (Backgroud : White)
 *
 * @param section box  section ?
 * @param e box   element
 * @throws Exception
 */
public static void setBoxW(Section section, Element e) throws Exception {

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(1);
    t.setSpacingAfter(12);

    if (e.getAttributeValue("width") != null)
        t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width")));

    PdfPCell cell = new PdfPCell();
    if (e.getAttributeValue("option") != null) {

        ColumnText col = new ColumnText(null);
        for (Element e1 : e.getChildren()) {
            if (e1.getAttributeValue("type").equals("red"))
                col.addText(new Phrase(e1.getText(), fnBoxRed));
            else
                col.addText(new Phrase(e1.getText(), fnBoxBlack));
        }
        cell.setColumn(col);

    } else {
        cell.setPhrase(new Phrase(e.getText(), fnBoxBlack));
    }

    cell.setPaddingLeft(10);
    cell.setLeading(0.0F, 1.8F);
    cell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(new BaseColor(255, 255, 255));

    t.addCell(cell);

    section.add(t);

}

From source file:com.quix.aia.cn.imo.mapper.ApplicationFormPDFMaintenance.java

License:Open Source License

private static Document ESingnature(Document document, PdfWriter writer, AddressBook addressbook) {
    // TODO Auto-generated method stub
    log.log(Level.INFO, "ApplicationFormPDFMaintenance --> ESingnature ");
    try {//from   ww  w  .  j  ava  2 s .  c o m

        document.newPage();

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

        PdfPCell c1 = new PdfPCell(new Phrase("E-singnature "));
        c1.setHorizontalAlignment(Element.ALIGN_LEFT);
        c1.setColspan(4);
        c1.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP);
        c1.setFixedHeight(30f);
        c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        c1.setBorder(Rectangle.BOX);
        c1.setFixedHeight(25f);
        table.addCell(c1);
        table.setHeaderRows(1);

        for (int i = 0; i < 2; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }

        Iterator itr = null;
        CandidateESignature esignature = new CandidateESignature();
        if (addressbook.getCandidateESignatures().size() > 0) {
            itr = addressbook.getCandidateESignatures().iterator();
            esignature = (CandidateESignature) itr.next();
        }

        c1 = new PdfPCell(new Phrase("Branch : " + esignature.getBranch(), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        c1.setBorder(Rectangle.BOTTOM);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Servicing Department : " + esignature.getServiceDepartment(), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        c1.setBorder(Rectangle.BOTTOM);
        table.addCell(c1);

        for (int i = 0; i < 2; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }

        c1 = new PdfPCell(new Phrase("City : " + esignature.getCity(), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        c1.setBorder(Rectangle.BOTTOM);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Agent Code : " + esignature.getAgentId(), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        c1.setBorder(Rectangle.BOTTOM);
        table.addCell(c1);

        for (int i = 0; i < 4; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }

        document.add(table);

        table = new PdfPTable(2);
        table.setSpacingBefore(10);
        table.setWidthPercentage(100f);
        table.setWidths(new int[] { 80, 20 });

        c1 = new PdfPCell(new Phrase("Presently attached with another insurance Company ?  ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Yes \t\t\t\t\t\t\t\t  No", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        for (int i = 0; i < 2; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);

        }

        c1 = new PdfPCell(
                new Phrase("Presently in contact with any other AIA'S servicing Department ?   ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Yes \t\t\t\t\t\t\t\t  No", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        for (int i = 0; i < 2; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);

        }

        c1 = new PdfPCell(
                new Phrase("Taken LOMBRA occupational test or PSP test in the past ?  If Yes, ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Yes \t\t\t\t\t\t\t\t  No", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        for (int i = 0; i < 2; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);

        }

        c1 = new PdfPCell(new Phrase("Please provide the result.  ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        for (int i = 0; i < 5; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }
        document.add(table);

        Paragraph para1 = new Paragraph();
        para1.add(new Chunk("Applicant's Declaration ", font));
        para1.setAlignment(Element.ALIGN_LEFT);
        para1.setSpacingAfter(5f);
        document.add(para1);

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

        for (int i = 0; i < 4; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);

            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }

        c1 = new PdfPCell(new Phrase("Application Date", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Applicant/Candidate Name  :", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        if (esignature.getApplicationDate() != null) {
            c1 = new PdfPCell(new Phrase(format.format(esignature.getApplicationDate()), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        } else {
            c1 = new PdfPCell(new Phrase("", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }

        c1 = new PdfPCell(new Phrase(esignature.getCandidateName(), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        for (int i = 0; i < 4; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);

            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }
        document.add(table);

        para1 = new Paragraph();
        para1.add(new Chunk("E-Signature  : ", font));
        para1.setAlignment(Element.ALIGN_LEFT);
        para1.setSpacingAfter(5f);
        document.add(para1);

        c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        if (esignature.geteSignaturePhoto() != null) {
            Image image = Image.getInstance(esignature.geteSignaturePhoto());
            para1 = new Paragraph();
            para1.add(image);
            para1.setAlignment(Element.ALIGN_LEFT);
            para1.setSpacingAfter(5f);
            document.add(para1);
        } else {
            para1 = new Paragraph();
            para1.add("");
            para1.setAlignment(Element.ALIGN_LEFT);
            para1.setSpacingAfter(5f);
            document.add(para1);
        }

    } catch (Exception e) {
        // TODO Auto-generated catch block
        log.log(Level.INFO, "ApplicationFormPDFMaintenance --> ESingnature " + e.getMessage());
        e.printStackTrace();
        e.printStackTrace();
        LogsMaintenance logsMain = new LogsMaintenance();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        logsMain.insertLogs("ApplicationFormPDFMaintenance", Level.SEVERE + "", errors.toString());
    }

    return document;
}

From source file:com.quix.aia.cn.imo.mapper.ApplicationFormPDFMaintenance.java

License:Open Source License

private static Document personalCertification(Document document, PdfWriter writer, AddressBook addressbook) {
    // TODO Auto-generated method stub
    log.log(Level.INFO, "ApplicationFormPDFMaintenance --> personalCertification ");
    try {//from   w  w  w  . j av a 2s .  com

        /*  New Page   */
        document.newPage();

        PdfPTable table = new PdfPTable(2);
        table.setSpacingBefore(10);
        table.setWidthPercentage(100f);
        int i = 0;

        for (Iterator itr = addressbook.getCandidateProfessionalCertifications().iterator(); itr.hasNext();) {
            CandidateProfessionalCertification procertification = (CandidateProfessionalCertification) itr
                    .next();
            if (i != 0) {
                PdfPCell c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);

                c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);
            }
            i++;
            PdfPCell c1 = new PdfPCell(new Phrase("PERSONAL CERTIFICATION"));
            c1.setHorizontalAlignment(Element.ALIGN_LEFT);
            c1.setColspan(4);
            c1.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP);
            c1.setFixedHeight(30f);
            c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
            c1.setBorder(Rectangle.BOX);
            c1.setFixedHeight(25f);
            table.addCell(c1);
            table.setHeaderRows(1);

            for (int j = 0; j < 2; j++) {
                c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);

            }

            c1 = new PdfPCell(new Phrase("Certificate Name: " + procertification.getCertificateName(), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

            c1 = new PdfPCell(new Phrase("Chrater Agency: " + procertification.getCharterAgency(), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

            for (int j = 0; j < 2; j++) {
                c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);

            }

            c1 = new PdfPCell(
                    new Phrase("Charter Date : " + format.format(procertification.getCharterDate()), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            //c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

        }

        document.add(table);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        log.log(Level.INFO, "ApplicationFormPDFMaintenance --> personalCertification " + e.getMessage());
        e.printStackTrace();
        e.printStackTrace();
        LogsMaintenance logsMain = new LogsMaintenance();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        logsMain.insertLogs("ApplicationFormPDFMaintenance", Level.SEVERE + "", errors.toString());
    }

    return document;
}

From source file:com.quix.aia.cn.imo.mapper.ApplicationFormPDFMaintenance.java

License:Open Source License

private static Document Education(Document document, PdfWriter writer, AddressBook addressbook) {
    // TODO Auto-generated method stub
    log.log(Level.INFO, "ApplicationFormPDFMaintenance --> Education ");
    try {/*from www .  j  a  v a 2s . co m*/

        /*  New Page   */
        document.newPage();

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

        int i = 0;
        for (Iterator itr = addressbook.getCandidateEducations().iterator(); itr.hasNext();) {
            CandidateEducation candidateEducation = (CandidateEducation) itr.next();
            if (i != 0) {
                PdfPCell c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);

                c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);
            }

            i++;
            PdfPCell c1 = new PdfPCell(new Phrase("EDUCATION"));
            c1.setHorizontalAlignment(Element.ALIGN_LEFT);
            c1.setColspan(4);
            c1.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP);
            c1.setFixedHeight(30f);
            c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
            c1.setBorder(Rectangle.BOX);
            c1.setFixedHeight(25f);
            table.addCell(c1);
            table.setHeaderRows(1);

            for (int j = 0; j < 2; j++) {
                c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);

            }

            c1 = new PdfPCell(
                    new Phrase("Start Date: " + format.format(candidateEducation.getStartDate()), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

            c1 = new PdfPCell(new Phrase("End Date: " + format.format(candidateEducation.getEndDate()), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

            for (int j = 0; j < 2; j++) {
                c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);

            }

            c1 = new PdfPCell(new Phrase("Witness : " + candidateEducation.getWitness(), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

            c1 = new PdfPCell(new Phrase("Education : " + candidateEducation.getEducation(), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

            for (int j = 0; j < 2; j++) {
                c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);

            }

            c1 = new PdfPCell(new Phrase("Education Level : " + candidateEducation.getEducationLevel(), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

            c1 = new PdfPCell(new Phrase("School : " + candidateEducation.getSchool(), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

            for (int j = 0; j < 2; j++) {
                c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);

            }

            c1 = new PdfPCell(
                    new Phrase("Witness Contect Number : " + candidateEducation.getWitnessContactNo(), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            //c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

        }
        document.add(table);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        log.log(Level.INFO, "ApplicationFormPDFMaintenance --> Education " + e.getMessage());
        e.printStackTrace();
        e.printStackTrace();
        LogsMaintenance logsMain = new LogsMaintenance();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        logsMain.insertLogs("ApplicationFormPDFMaintenance", Level.SEVERE + "", errors.toString());
    }

    return document;
}