<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    <%@page import="com.csc.library.utility.DHMConvert" %>
    <%@page import="java.util.ArrayList" %>
    <%@page import="java.util.Iterator" %>
    <%@page import="java.util.Vector" %>
    <%@page import="java.util.*" %>
    <%@page import="com.csc.library.report.ReportUDF" %>
    <%@page import="javax.servlet.jsp.jstl.sql.Result" %>
    <%@page import="java.io.FileOutputStream" %>
    <%@page import="java.io.OutputStream" %>
    <%@page import="java.io.ByteArrayOutputStream" %>
    <%@page import="java.net.URLDecoder" %>
    <%@page import="java.text.DecimalFormat" %>
    <%@page import="java.net.URLEncoder" %>
    <%@page import="java.util.HashMap" %>
    <%@page import="java.text.SimpleDateFormat" %>
    <%@page import="java.util.Locale" %>
    <%@page import="java.util.Date" %>
    <%@page import="java.util.GregorianCalendar" %>
    <%@page import="com.csc.library.database.DataSet" %>
    <%@page import="com.csc.library.session.InitialInquiry" %>
    <%@page import="com.csc.library.session.InitialRecord" %>
    <%@page import="com.csc.library.session.DbInquiry" %>
    <%@page import="com.csc.library.session.DbRecord" %>
    <%@page import="com.csc.library.entry.HelpEntry" %>
    <%@page import="com.itextpdf.text.*" %>
    <%@page import="com.itextpdf.text.pdf.*" %>
    <%@page import="java.io.ByteArrayOutputStream" %>
    <%@page import="com.csc.library.session.InitialEnvironment" %>
    <%@page import="java.io.File" %>
    <%@page import="org.json.JSONArray" %>
    <%@page import="org.json.JSONObject" %>
    <%@page import="com.csc.library.utilities.*" %>
    <%@ page import="com.csc.library.databean.Simmcandidatewithgson" %>
    <%@ page import="com.csc.library.database.MyHashMap" %>
    <%@ page import="com.csc.library.utilities.gsonmapping.*" %>
    <jsp:useBean id="CandidatePrint_PLANETCOMM" class="com.csc.library.system.Task" scope="page"/>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8"/>
    <title>Report</title>
    </head>
    <body>
    <%
    CandidatePrint_PLANETCOMM.setChannel(request, response);
    HelpEntry screen = (HelpEntry) CandidatePrint_PLANETCOMM.process("HelpEntry", "MCANDIDATEHELP");
    CheckNull chk = new CheckNull();
    String filter = "APPLICANTID = '" + chk.chkNullString(request.getParameter("appid")) + "'";
    //    filter = "1=2";
    screen.setMaxLine(1);
    screen.inq.setFilter(filter);
    screen.process();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();//72
    Document document = new Document(PageSize.A4, 18, 18, 20, 0);// Left,Right,Top,Down
    float[] sizeColumn = new float[]{};
    PdfWriter writer = PdfWriter.getInstance(document, baos);

    //ADD HEADER FOOTER
    HeaderFooterPageEvent event = new HeaderFooterPageEvent();
    writer.setPageEvent(event);
    document.open();
    document.addTitle("Document Title");
    //MAKE ADD BORDER PDF PAGE
    Rectangle rect= new Rectangle(577,620,18,68); // you can resize rectangle     
    rect.enableBorderSide(1);
    rect.enableBorderSide(2);
    rect.enableBorderSide(4);
    rect.enableBorderSide(8);
    rect.setBorderColor(BaseColor.BLACK);
    rect.setBorderWidth(1);
    document.add(rect); //SET ADD BORDER PDF PAGE 1

    // Setting Fonts
    BaseFont bfWithFontAWesome = BaseFont.createFont(application.getRealPath("fonts/FontAwesome.otf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    BaseFont bf = BaseFont.createFont(application.getRealPath("fonts/Cordia.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    BaseFont bfHead = BaseFont.createFont(application.getRealPath("fonts/Cordia.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED, true);
    Font font = new Font(bf, 11);
    Font fontTopic = new Font(bfHead, 13);  
    Font fontHead = new Font(bfHead, 13, Font.BOLD);
    Font fontHeadWhiteColor = new Font(bfHead, 12, Font.BOLD, new BaseColor(255, 255, 255));
    fontHead.setStyle(Font.BOLD);
    Font fontContent = new Font(bfHead, 10);
    Font fontContent01 = new Font(bfHead, 9);
    Font fontBoldContent = new Font(bfHead, 11, Font.BOLD);
    Font fontTitle = new Font(bfHead, 20, Font.BOLD);
    fontTitle.setStyle(Font.BOLD);
    Font fontAwesome = new Font(bfWithFontAWesome, 10);
    //setfonts
    Font font_C18B = new Font(bfHead, 18, Font.BOLD);
    Font font_C16B = new Font(bfHead, 16, Font.BOLD);
    Font font_C13B = new Font(bfHead, 13,Font.BOLD);
    Font font_C13N = new Font(bfHead, 13);
    Font font_C12B = new Font(bfHead, 12,Font.BOLD);
    Font font_C12N = new Font(bfHead, 12);
    Font font_C10N = new Font(bfHead, 10);
    Font font_C09N = new Font(bfHead, 9);
    Font font_C08N = new Font(bfHead, 8);
    Font linebreak = new Font(bfHead, 1);
    // set vlign middle
    String[] text2 = new String[2];
    Phrase content = new Phrase(new Chunk("",linebreak));
    Float fontSize = content.getFont().getSize();
    Float capHeight = content.getFont().getBaseFont().getFontDescriptor(BaseFont.CAPHEIGHT, fontSize);
    boolean langthai = screen.getUProfile().get("lang").equalsIgnoreCase("THA");

    boolean hasData = false;
    if (screen.getInquiry().recCount() > 0) {
      hasData = true;
      screen.nextRec();
      screen.referLangOn();
      DbInquiry dbinq = null;
      int i = 0;
      
      Simmcandidatewithgson simmcandidatewithgson = (Simmcandidatewithgson) screen.inq.getCurrentDbRecord();

      //------------------------------------age------------------------------------
      
      String age_memployee = "";
      CscCalendar startDate = new CscCalendar( chk.chkNullString(simmcandidatewithgson.mcandidatePersonal.birthdate.substring(0,10),"2100-12-31"));
      CscCalendar endDate = new CscCalendar();
      CountAge count = new CountAge(screen.getUProfile().get("lang"));
      age_memployee = chk.chkNullString(count.getCountAges(startDate,endDate,true),"0");
  
      String prefixDescTH = "";
      String prefixDescEN = "";
      String prefixid = simmcandidatewithgson.mcandidatePersonal.prefixid;
      DbInquiry inqprefixid = new InitialInquiry(screen.getUProfile()).getDbInquiry("mprefix");
      inqprefixid.setFilter("prefixid = '" + prefixid + "'");
      inqprefixid.refresh();
      while (inqprefixid.next()) {
        prefixDescTH = inqprefixid.getString("tdesc");
        prefixDescEN = inqprefixid.getString("edesc");
      }

      //------------------------------------end age------------------------------------
      //----------------------------SourceJOB------------------------------------
      String sourcejobDesc = "";
      String Sim_sourcejobID = "";
      if(simmcandidatewithgson.mcandidateOther.sourcejob.equals(null)||simmcandidatewithgson.mcandidateOther.sourcejob.equals("")){
        Sim_sourcejobID = "0";
      }
      else{
        Sim_sourcejobID = "0";
      }

      DbInquiry inqmsourcejob = new InitialInquiry(screen.getUProfile()).getDbInquiry("msourcejob");
      inqmsourcejob.setFilter("sourcejobid = '" + Sim_sourcejobID + "'");
      inqmsourcejob.refresh();
      while (inqmsourcejob.next()) {
        sourcejobDesc = inqmsourcejob.getString("tdesc");
      }
        String job_from =  chk.chkNullString(simmcandidatewithgson.mcandidateOther.sourcejob," ");
        String sourcejobExplain  = chk.chkNullString(simmcandidatewithgson.mcandidateOther.sourcejobExplain," ");
        String typejobfrom = "";
        String str_job_from0 = "";
        String str_job_from2 = "";
        String str_job_from3 = "";
        if (job_from.equalsIgnoreCase("2") || job_from.equalsIgnoreCase("3") ||job_from.equalsIgnoreCase("4") ||job_from.equalsIgnoreCase("5") ||job_from.equalsIgnoreCase("326") ){
          typejobfrom = "0";
          str_job_from0 =  sourcejobExplain;
        }
        //Career Fair
        else if(job_from.equalsIgnoreCase("7")){
          typejobfrom = "1";
        } 
        //Friend to Friend
        else if(job_from.equalsIgnoreCase("327")){
          typejobfrom = "2";
          str_job_from2 =  sourcejobExplain;
        }
        //line,Walk In,Facebook,Other"'6','8','10','9'"
        else if (job_from.equalsIgnoreCase("6") ||job_from.equalsIgnoreCase("8") ||job_from.equalsIgnoreCase("9") ||job_from.equalsIgnoreCase("10") ){
          typejobfrom = "3";
         
          if(job_from.equalsIgnoreCase("9")){
            str_job_from3 =  sourcejobExplain;
          }
          else{
            str_job_from3 =  sourcejobExplain;
          }
        }
      //----------------------------END SourceJOB------------------------------------
      //----------------------------nationa------------------------------------
      String nationadesc = "";
      String Sim_nationaID = "";
      if(simmcandidatewithgson.mcandidatePersonal.nationalityid.equals(null) || simmcandidatewithgson.mcandidatePersonal.nationalityid.equals("")){
        Sim_nationaID = "0";
      }
      else{
        Sim_nationaID = simmcandidatewithgson.mcandidatePersonal.nationalityid;
      }
      DbInquiry inqmnational = new InitialInquiry(screen.getUProfile()).getDbInquiry("mnational");
      inqmnational.setFilter("nationalid = '" + Sim_nationaID + "'");
      inqmnational.refresh();

      while (inqmnational.next()) {
        inqmnational.referLangOn();
        nationadesc = inqmnational.getString("tdesc");        
      }
      //----------------------------END nationa------------------------------------

      //----------------------------nationality------------------------------------
      String nationalityDesc = "";
      String Sim_nationalityID = "";    
      if(simmcandidatewithgson.mcandidatePersonal.nationalityid.equals(null)){
        Sim_nationalityID = "0";
      }
      else{
        Sim_nationalityID = simmcandidatewithgson.mcandidatePersonal.raceid;
      }

      DbInquiry inqMnationality = new InitialInquiry(screen.getUProfile()).getDbInquiry("Mnationality");
      inqMnationality.setFilter("nationalityid = '" + Sim_nationalityID + "'");
      inqMnationality.refresh();
      while (inqMnationality.next()) {
        inqMnationality.referLangOn();
        nationalityDesc = inqMnationality.getString("tdesc");      
      }
      //----------------------------END nationality------------------------------------

      // ----------------------------religion------------------------------------
      String religionDesc = "";
      String Sim_religionID = "";
      if(simmcandidatewithgson.mcandidatePersonal.religionid.equals(null)){
        Sim_religionID = "0";
      }
      else{
        Sim_religionID = simmcandidatewithgson.mcandidatePersonal.religionid;
      }
      DbInquiry inqmreligion = new InitialInquiry(screen.getUProfile()).getDbInquiry("mreligion");
      inqmreligion.setFilter("religionid = '"+Sim_religionID+"'");
      inqmreligion.refresh();
      while(inqmreligion.next()){
        inqmreligion.referLangOn();
        religionDesc = inqmreligion.getString("tdesc");
      }
      //----------------------------END religion------------------------------------

      //----------------------------SETDATA CONTACT ------------------------------------
      StringBuilder sc = new StringBuilder();
      sc.append(simmcandidatewithgson.mcandidateContact.current.addr);
      if (!simmcandidatewithgson.mcandidateContact.home.moo.equalsIgnoreCase("-")) {
        sc.append(" หมู่ " + simmcandidatewithgson.mcandidateContact.home.moo);
      }
      sc.append(" ถนน " + simmcandidatewithgson.mcandidateContact.home.road);
      //----------------------------END CONTACT------------------------------------
      //----------------------------SETDATA EDUCATION------------------------------------
      MyHashMap educationbackground = new MyHashMap();
      String[] masterdegree = {"1", "2", "3","4", "5", "6", "7", "8", "9", "10", "11", "12"};
      
      String degreeDesc = "";
      String majorDesc = "";
      for (String degreekey : masterdegree) {
        educationbackground.put("nameth" + degreekey, " ");
        educationbackground.put("nameen" + degreekey, " ");
        educationbackground.put("from" + degreekey, " ");
        educationbackground.put("to" + degreekey, " ");
        educationbackground.put("degree" + degreekey, " ");
        educationbackground.put("majorth" + degreekey, " ");
        educationbackground.put("majoren" + degreekey, " ");
        educationbackground.put("gpa" + degreekey, " ");
      }
      DbInquiry inqdegree = new InitialInquiry(screen.getUProfile()).getDbInquiry("mdegree");
      DbInquiry inqmajor = new InitialInquiry(screen.getUProfile()).getDbInquiry("mmajor");
      for (McandidateEducation.Education education : simmcandidatewithgson.mcandidateEducation.education) {
      // set 2 lang
        if (education.university.universitylist == null) {
          educationbackground.put("nameth" + education.degreetype, education.university.searchtext);
          educationbackground.put("nameen" + education.degreetype, education.university.searchtext);
        } else {
          educationbackground.put("nameth" + education.degreetype, education.university.universitylist.name.tha);
          educationbackground.put("nameen" + education.degreetype, education.university.universitylist.name.eng);
        }
        if (education.major.majorlist == null) {
          educationbackground.put("majorth" + education.degreetype, education.major.searchtext);
          educationbackground.put("majoren" + education.degreetype, education.major.searchtext);
        }else {
          educationbackground.put("majorth" + education.degreetype, education.major.majorlist.name.tha);
           educationbackground.put("majoren" + education.degreetype, education.major.majorlist.name.eng);
        }
        educationbackground.put("from" + education.degreetype, education.yearstart);
        educationbackground.put("to" + education.degreetype, education.yearend);
        educationbackground.put("gpa" + education.degreetype, education.gpa);
      }

      //----------------------------SET DATA Family------------------------------------
      //01 father ,02 mother ,03 Spouse's name ,99 emergency
      //09 Child
      //14  siblings = 140, 141, 142
      MyHashMap familybackground = new MyHashMap();
      String[] masterrelations = {"01", "02", "03" ,"04", "05", "06" ,"07", "08", "09" ,"10", "11", "12" ,"14","99","140","141","142"};
      String occupationDesc = "";
      String line = "";
      int childtotal = 0;
      int relativetotal = 0;
      int siblings = 0;
      for (String relatationkey : masterrelations) {
        if(relatationkey.equals("14")){
            familybackground.put("fname" + relatationkey + siblings, "");
            familybackground.put("lname" + relatationkey + siblings, "");
            familybackground.put("age" + relatationkey + siblings, "");
            familybackground.put("occupation" + relatationkey + siblings, "");
            familybackground.put("position" + relatationkey + siblings, "");
            familybackground.put("status" + relatationkey + siblings, "");
            familybackground.put("workplace" + relatationkey + siblings, "");
            familybackground.put("phone" + relatationkey + siblings, "");    
            siblings++;
          }
        else{
            familybackground.put("fname" + relatationkey, "");
            familybackground.put("lname" + relatationkey, "");
            familybackground.put("age" + relatationkey, "");
            familybackground.put("occupation" + relatationkey, "");
            familybackground.put("position" + relatationkey, "");
            familybackground.put("status" + relatationkey, "");
            familybackground.put("workplace" + relatationkey, "");
            familybackground.put("phone" + relatationkey, "");  
          }  
        }
      familybackground.putToSum("nameallchild", "");
      familybackground.putToSum("ageallchild", "");
      familybackground.putToSum("occupationallchild", "");
      familybackground.putToSum("positionallchild", "");
      familybackground.putToSum("statusallchild", "");
      familybackground.putToSum("workplaceandphoneallchild", "");

      familybackground.putToSum("nameallrelative", "");
      familybackground.putToSum("ageallrelative", "");
      familybackground.putToSum("occupationallchild", "");
      familybackground.putToSum("positionallchild", "");
      familybackground.putToSum("statusallrelative", "");
      familybackground.putToSum("workplaceandphoneallrelative", "");

      DbInquiry inqoccupation = new InitialInquiry(screen.getUProfile()).getDbInquiry("moccupation");
      siblings = 0;
      String nameallchild = "";
      String ageallchild = "";
      String occupationallchild = "";
      String positionallchild = "";
      String statusallchild = "";
      String workplaceandphoneallchild = "";

      String nameallrelative = "";
      String ageallrelative = "";
      String occupationallrelative = "";
      String positionallrelative = "";
      String statusallrelative = "";
      String workplaceandphoneallrelative = "";
      String workplaceallrelative = "";
      for (McandidateFamily.Family family : simmcandidatewithgson.mcandidateFamily.family) {
        inqoccupation.setFilter("occid = '" + family.occupation+ "'");
        inqoccupation.refresh();
        while (inqoccupation.next()) {
          inqoccupation.referLangOn();
          occupationDesc = inqoccupation.getString("tdesc");
        }
        //siblings 140 141 142
          if(family.relation.equals("14")){
            familybackground.put("fname" + family.relation + siblings, chk.chkNullString(family.fname));
            familybackground.put("lname" + family.relation + siblings, family.lname);
            familybackground.put("age" + family.relation + siblings, family.age);
            familybackground.put("occupation" + family.relation + siblings, occupationDesc);
            familybackground.put("position" + family.relation + siblings, family.position);
            familybackground.put("status" + family.relation + siblings, family.status);
            familybackground.put("workplace" + family.relation + siblings, family.workplace);
            familybackground.put("phone" + family.relation + siblings, family.phone);
            siblings++;
          }
          else{
            familybackground.put("fname" + family.relation, family.fname);
            familybackground.put("lname" + family.relation, family.lname);
            familybackground.put("age" + family.relation, family.age);
            familybackground.put("occupation" + family.relation, occupationDesc);
            familybackground.put("position" + family.relation, family.position);
            familybackground.put("status" + family.relation, family.status);
            familybackground.put("workplace" + family.relation, family.workplace);
            familybackground.put("phone" + family.relation, family.phone);
          }
        if ("09,10,11,12,".indexOf(family.relation) > -1) {
          if (childtotal > 0) {
            line = System.lineSeparator();
          }
          nameallchild += line + family.fname + " " + family.lname;
          ageallchild += line + family.age;
          occupationallchild += line + occupationDesc;
          positionallchild += line + family.position;
          statusallchild += line + family.status;
          workplaceandphoneallchild += line + family.workplace + " " + family.phone;
      //    workplaceallchild += line + family.workplace;
          childtotal++;
          
        }
        if ("14,".indexOf(family.relation) > -1) {
          if (relativetotal > 0) {
            line = System.lineSeparator();
          }
          nameallrelative += line + family.fname + " " + family.lname;
          ageallrelative += line + family.age;
          occupationallrelative += line + occupationDesc;
          positionallrelative += line + family.position;
          statusallrelative += line + family.status;
          workplaceandphoneallrelative += line + family.workplace + " " + family.phone;
          workplaceallrelative += line + family.workplace;
          relativetotal++;
          }
        
        familybackground.putToSum("nameallchild", nameallchild);
        familybackground.putToSum("ageallchild", ageallchild);
        familybackground.putToSum("occupationallchild", occupationallchild);
        familybackground.putToSum("positionallchild", positionallchild);
        familybackground.putToSum("statusallchild", line + statusallchild);
        familybackground.putToSum("workplaceandphoneallchild", workplaceandphoneallchild);

        familybackground.put("nameallrelative", nameallrelative);
        familybackground.put("ageallrelative", ageallrelative);
        familybackground.put("occupationallrelative", occupationallrelative);
        familybackground.put("positionallrelative" , positionallrelative);
        familybackground.put("statusallrelative", statusallrelative);
        familybackground.put("workplaceandphoneallrelative" , workplaceandphoneallrelative);
        familybackground.put("workplaceallrelative", workplaceallrelative);
      }
      //----------------------------END Family------------------------------------
      DecimalFormat DFO = new DecimalFormat("#,###,###");
      DecimalFormat DFO_ietls = new DecimalFormat("#,###.##");
      //----------------------------SETDATA Skill ------------------------------------
      MyHashMap hmlangskill = new MyHashMap();
      MyHashMap masterskilllevel = new MyHashMap();
      int langskillloop = 0;

      for(int initlangskill = 0; initlangskill <= 4; initlangskill++){
        hmlangskill.put("skillNameTdesc"+initlangskill, " ");
        hmlangskill.put("skillNameEdesc"+initlangskill, " ");
        hmlangskill.put("reading"+initlangskill,  " ");
        hmlangskill.put("write"+initlangskill, " ");
        hmlangskill.put("speak"+initlangskill, " ");
        hmlangskill.put("listen"+initlangskill, " ");
        hmlangskill.put("searchtext"+initlangskill, " ");
      }      
      DbInquiry inqskilllevel = new InitialInquiry(screen.getUProfile()).getDbInquiry("mskilllevel");
      inqskilllevel.refresh();
      while(inqskilllevel.next()) {
        inqskilllevel.referLangOn();
        masterskilllevel.put(inqskilllevel.getString("skilllevelid"),inqskilllevel.getString("tdesc"));
      }

  //    DbInquiry inqlangskill = new InitialInquiry(screen.getUProfile()).getDbInquiry("mlanguage");
      for (McandidateSkill.Langskill langskill : simmcandidatewithgson.mcandidateSkill.langskill) {
   /*     inqlangskill.setFilter("languageid = '"+langskill.name+"'");
        inqlangskill.refresh();

        while(inqlangskill.next()) {
          inqlangskill.referLangOff();
          hmlangskill.put("skillNameTdesc"+langskillloop, inqlangskill.getString("tha"));
          hmlangskill.put("skillNameEdesc"+langskillloop, inqlangskill.getString("eng"));
        }
*/
        if(langskill.langskilllist == null){
          hmlangskill.put("skillNameTdesc"+langskillloop, langskill.searchtext);
        }
        else{
          hmlangskill.put("skillNameTdesc"+langskillloop, chk.chkNullString(langskill.langskilllist.name.tha," "));
          hmlangskill.put("skillNameEdesc"+langskillloop, chk.chkNullString(langskill.langskilllist.name.eng," "));
        }

        hmlangskill.put("reading"+langskillloop, chk.chkNullString( masterskilllevel.get(langskill.skill.reading).toString()," "));
        hmlangskill.put("write"+langskillloop, chk.chkNullString( masterskilllevel.get(langskill.skill.write).toString()," "));
        hmlangskill.put("speak"+langskillloop, chk.chkNullString( masterskilllevel.get(langskill.skill.speak).toString()," "));
        hmlangskill.put("listen"+langskillloop, chk.chkNullString( masterskilllevel.get(langskill.skill.listen).toString()," "));
        
        langskillloop++;
      }
     
      //----------------------------End Skill ----------------------------------------
      //----------------------------JSONArray activity ----------------------------------------
      JSONArray activityAry = new JSONArray(simmcandidatewithgson.mcandidateSkill.activity);
      String activityList = "";

      for (int activityloop = 0 ; activityloop < activityAry.length() ; activityloop++) {
        activityList += activityAry.getJSONObject(activityloop).getString("name");
          if(activityloop + 1 < activityAry.length()){
              activityList += ",";
          }
      }
      
      //----------------------------END JSONArray activity ----------------------------------------
      //----------------------------Check Overtime & Work_country ----------------------------------------
        Boolean chk_overtime =simmcandidatewithgson.mcandidateOther.overtime.status;
        Boolean chk_workup_country =simmcandidatewithgson.mcandidateOther.workupcountry;
        String overtime="";
        if(chk_overtime == null)
        { overtime = "1";}
        else if(chk_overtime != null){
              if(chk_overtime)
              { overtime = "0";}
              else
              { overtime = "2";}
        }
        String workup_country="";
         if(chk_workup_country == null)
        { workup_country = "1";}
        else if(chk_workup_country != null){
              if(chk_workup_country)
              { workup_country = "0";}
              else
              { workup_country = "2";}
        }
      //----------------------------END Overtime & Work_country ----------------------------------------
      //----------------------------BLOOD ----------------------------------------
          String chk_blood  = simmcandidatewithgson.mcandidatePersonal.blood;

      //----------------------------JSONArray hobbies ----------------------------------------
      JSONArray hobbiesAry = new JSONArray(simmcandidatewithgson.mcandidateSkill.hobbies);
      String hobbieList = "";

      for (int hobbiesloop = 0 ; hobbiesloop < hobbiesAry.length() ; hobbiesloop++) {
        hobbieList += hobbiesAry.getString(hobbiesloop);
          if(hobbiesloop + 1 < hobbiesAry.length()){
              hobbieList += ",";
          }
      }
      //----------------------------END JSONArray hobbies ----------------------------------------
      //----------------------------SETDATA JOPEXP------------------------------------
      MyHashMap jobexp = new MyHashMap();
      String[] AddressJob = new String[4];
      int roundjobexp = 0;
      for (int jobexpkey = 0; jobexpkey <= 10; jobexpkey++){
        jobexp.put("companyname_job" + jobexpkey, " ");
        jobexp.put("start" + jobexpkey, " ");
        jobexp.put("end" + jobexpkey, " ");
        jobexp.put("title" + jobexpkey, " ");
        jobexp.put("salary" + jobexpkey, " ");
        jobexp.put("endingsalary" + jobexpkey, " ");
        jobexp.put("reason" + jobexpkey, " ");
        jobexp.put("present" + jobexpkey , " ");
        jobexp.put("description" + jobexpkey , " ");
        //AddressJob
        jobexp.put("addr" + jobexpkey , " ");
        jobexp.put("village" + jobexpkey , " ");
        jobexp.put("roomNo" + jobexpkey , " ");
        jobexp.put("floor" + jobexpkey , " ");
        jobexp.put("soi" + jobexpkey , " ");
        jobexp.put("moo" + jobexpkey , " ");
        jobexp.put("road" + jobexpkey , " ");
        jobexp.put("district" + jobexpkey , " ");
        jobexp.put("disname" + jobexpkey , " ");
        jobexp.put("proname" + jobexpkey , " ");
        jobexp.put("zipid" + jobexpkey , " ");
      }
      for (McandidateJobExp.Job job : simmcandidatewithgson.mcandidateJobExp.job) {

        jobexp.put("companyname_job" + roundjobexp,job.companyname);
        jobexp.put("start" + roundjobexp,new CscCalendar(job.start.toString().substring(0,10)).getDDMMYYYY().replaceAll("-","/"));
        jobexp.put("end" + roundjobexp, new CscCalendar(job.end.toString().substring(0,10)).getDDMMYYYY().replaceAll("-","/"));
        jobexp.put("title" + roundjobexp, job.title);
        jobexp.put("salary" + roundjobexp, DFO.format(Integer.valueOf(chk.chkNullString(job.salary,"0") )));
        jobexp.put("endingsalary" + roundjobexp, DFO.format(Integer.valueOf(chk.chkNullString(job.endingsalary,"0") )));
        jobexp.put("reason" + roundjobexp, job.reason);
        jobexp.put("present" + roundjobexp, job.present);
        jobexp.put("description" + roundjobexp, job.description);
        
        //AddressJob
        jobexp.put("addr" + roundjobexp , job.addr);
        jobexp.put("village" + roundjobexp , job.village);
        jobexp.put("roomNo" + roundjobexp , job.roomNo);
        jobexp.put("floor" + roundjobexp , job.floor);
        jobexp.put("soi" + roundjobexp , job.soi);
        jobexp.put("moo" + roundjobexp , job.moo);
        jobexp.put("road" + roundjobexp , job.road);
        jobexp.put("district" + roundjobexp , job.district);
        jobexp.put("disname" + roundjobexp , job.zipcode.disname.tha);
        jobexp.put("proname" + roundjobexp , job.zipcode.proname.tha);
        jobexp.put("zipid" + roundjobexp , job.zipcode.zipid);

        
        AddressJob[roundjobexp] = "เลขที่ "+ jobexp.get("addr"+roundjobexp).toString()+" " ;
        AddressJob[roundjobexp] += jobexp.get("village"+roundjobexp).toString() +" "  ;
        AddressJob[roundjobexp] += "ห้องเลขที่ " +jobexp.get("roomNo"+roundjobexp).toString() +" "  ;
        AddressJob[roundjobexp] += "ชั้น " + jobexp.get("floor"+roundjobexp).toString() +" "  ;
        AddressJob[roundjobexp] += "ซ." + jobexp.get("soi"+roundjobexp).toString() +" "  ;
        AddressJob[roundjobexp] += "หมู่ " + jobexp.get("moo"+roundjobexp).toString() +" "  ;
        AddressJob[roundjobexp] += "ถนน " + jobexp.get("road"+roundjobexp).toString() +" "  ;
        AddressJob[roundjobexp] += jobexp.get("district"+roundjobexp).toString() +" "  ;
        AddressJob[roundjobexp] += jobexp.get("disname"+roundjobexp).toString() +" "  ;
        AddressJob[roundjobexp] += jobexp.get("proname"+roundjobexp).toString() +" "  ;
        AddressJob[roundjobexp] += jobexp.get("zipid"+roundjobexp).toString() +" "  ;

        roundjobexp++;
      }
    //    new CscCalendar(jobexp.get("end2").toString().substring(0,10)).getDDMMYYYY()
      //----------------------------END JOPEXP------------------------------------

      //----------------------------SETDATA REFERENCE ------------------------------------
      MyHashMap familyreference = new MyHashMap();
      int roundreference = 0;

      for (int referencekey = 0; referencekey <= 5; referencekey++){
        familyreference.put("name" + referencekey, "");
        familyreference.put("jobtitle" + referencekey, "");
        familyreference.put("phone" + referencekey, "");
        familyreference.put("companyname" + referencekey, "");
        familyreference.put("relations" + referencekey, "");
        familyreference.put("address" + referencekey, "");
      }
      for (McandidateFamily.Reference reference : simmcandidatewithgson.mcandidateFamily.reference) {
        familyreference.put("name" + roundreference, reference.name);
        familyreference.put("jobtitle" + roundreference, reference.jobtitle);
        familyreference.put("phone" + roundreference, reference.phone);
        familyreference.put("companyname" + roundreference, reference.companyname);
        familyreference.put("relations" + roundreference, reference.relations);
        familyreference.put("address" + roundreference, reference.address);
        roundreference++;
      }
      //----------------------------END REFERENCE-----------------------------------------
      //----------------------------SETDATA JOBEXP TRAINING ------------------------------------
      MyHashMap jobexp_training = new MyHashMap();
      int roundtraining = 0;

      for (int trainingkey = 0; trainingkey <= 5; trainingkey++){
        jobexp_training.put("certificate" + trainingkey, "");
        jobexp_training.put("name" + trainingkey, "");
        jobexp_training.put("by" + trainingkey, "");
        jobexp_training.put("start" + trainingkey, "");
        jobexp_training.put("end" + trainingkey, "");
      }
      for (McandidateJobExp.Training training : simmcandidatewithgson.mcandidateJobExp.training) {
        jobexp_training.put("certificate" + roundtraining, training.certificate);
        jobexp_training.put("name" + roundtraining, training.name);
        jobexp_training.put("by" + roundtraining, training.by);
        jobexp_training.put("start" + roundtraining, new CscCalendar(training.start.toString().substring(0,10)).getDDMMYYYY().replaceAll("-","/"));
        jobexp_training.put("end" + roundtraining,new CscCalendar(training.end.toString().substring(0,10)).getDDMMYYYY().replaceAll("-","/"));
        roundtraining++;
      }
    //----------------------------END JOBEXP TRAINING-----------------------------------------


    try {
      CscCalendar calendar = new CscCalendar();
      GregorianCalendar gc = new GregorianCalendar();
    //  boolean langthai = screen.getUProfile().get("lang").equalsIgnoreCase("THA");
      String reportname = "", printdate = "", printby = "", refer = "RTA2007";
      String reportname_label = "", printdate_label = "", prdate = "", refer_label = "";
      if (langthai) {
      reportname_label = "รายงาน :";
      reportname = "รายงานข้อมูลพนักงาน";
      printdate_label = "วันที่พิมพ์ :";
      prdate = calendar.getDDMMYYYY();
      printdate = "วัน" + calendar.getLongThiDOW() + "ที่ " + calendar.getDate() + " " + calendar.getThaiLongMonth() + " พ.ศ. " + calendar.getThaiYYYY() + " " + calendar.getHHMM() + " น.";
      printby = screen.getUProfile().get("tfullname");
      refer_label = "อ้างอิง #";
      } else {
      reportname_label = "Report Name :";
      reportname = "Personal Report";
      printdate_label = "Print Date :";
      printby = screen.getUProfile().get("efullname");
      refer_label = "Ref #";
    }

    // --------------- new line -----------------

      sizeColumn = new float[]{50.0f,50.0f};
      PdfPTable detail = new PdfPTable(2);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      PdfPCell cellDetailHeader;
      PdfPCell cellDetail;
      Image imgHeader = null;
      Image img = null;
      //Image logo= new Image(ImageDataFactory.create(IMG));
      setPaddingTop(0.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(0.5f);

      DbInquiry mcom = new InitialInquiry(screen.getUProfile()).getDbInquiry("mcompany");
      mcom.setColumn("logo");
      mcom.setFilter("companyid='100'");
      mcom.refresh();
      mcom.next();
      imgHeader = Image.getInstance(getImagePath("COMPANY_UPLOAD-dir","LOGO/",mcom.getString("logo"),"default.png"));
      imgHeader.scaleToFit(200f, 200f);
      cellDetailHeader = new PdfPCell(imgHeader, false);
      cellDetailHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
      cellDetailHeader.setVerticalAlignment (Element.ALIGN_TOP);
      mcom.closeConnection();
   //   cellDetail.setColspan(2);
      cellDetailHeader.setFixedHeight(10.0f);
     // cellDetailHeader.setRowspan(6);
      cellDetailHeader.setBorder(Rectangle.NO_BORDER);
      detail.addCell(cellDetailHeader);

      Chunk Head1 = new Chunk("Planet Communications Asia PLC.\n",font_C12B);
      Chunk Head2 = new Chunk("157 SoiRamindra 34 , Ramindra Road,\n",font_C12N);
      Chunk Head3 = new Chunk("Tarang , Bangkhen, Bangkok 10230 Thailand\n",font_C12N);
      Chunk Head4 = new Chunk("Tel: (662) 792-2400 Fax: (662) 792-2499\n",font_C12N);
      Chunk Head5 = new Chunk("Email: info@planetcomm.com\n",font_C12N);
      Chunk Head6 = new Chunk("Web Site: http:/" + "/www.planetcomm.com",font_C12N);

      content = new Phrase();
      content.add(Head1);
      content.add(Head2);
      content.add(Head3);
      content.add(Head4);
      content.add(Head5);
      content.add(Head6);

      detail.addCell(getCellData2( content, "NO", "RIGHT", "MIDDLE",  1,  1) );
      detail.addCell(getCellData(" ", font_C12B, "NO", "RIGHT", "MIDDLE", 2, 1));
      document.add(detail);

      // --------------- new line -----------------
      sizeColumn = new float[]{20.0f,60.0f,20.0f};
      detail = new PdfPTable(3);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(0.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(0.5f);
      setBaseBackgroundColor(0,0,0); 
      detail.addCell(getCellData(" ", font_C12B, "NO", "CENTER", "MIDDLE", 1, 1, false,false));
      detail.addCell(getCellData("EMPLOYENT APPLICATION FORM", font_C18B, "NO", "CENTER", "BOTTOM", 1, 1, false,false));

      try{
        img = Image.getInstance(getImagePath("RECRUIT_UPLOAD-dir","PICTURE/",simmcandidatewithgson.mcandidatePersonal.imgname,"DEFAULTPERSON.jpg"));
        cellDetail = new PdfPCell(img, true);
        cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
        cellDetail.setFixedHeight(110);
      //cellDetail.setBorder(Rectangle.NO_BORDER);
        detail.addCell(cellDetail);
      }
      catch (Exception e) {
        detail.addCell(getCellData("NO PIC", font_C16B, "", "CENTER", "MIDDLE", 1, 1));
      } 
      document.add(detail);

      // --------------- new line -----------------
      //------------------------------------genderid------------------------------------
      int genderid =  simmcandidatewithgson.mcandidatePersonal.genderid;
      String gender = null ;
      if(genderid == 1){
         if (langthai)   {gender = "ชาย";}  else    {gender = "Male";}
      }else if (genderid == 2){
        if (langthai)   {gender = "หญิง";}  else  {gender = "Female";}
      }
      //------------------------------------end genderid------------------------------------
      sizeColumn = new float[]{17.0f,30.0f,20.0f,20.0f,10.0f};
      detail = new PdfPTable(5);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(10.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("POSITION APPLIED FOR", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(langthai? screen.getString("MJOBCODE", "TDESC"):screen.getString("MJOBCODE", "EDESC"), font_C12N, "R_BOTTOM", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData("EXPECTED SALARY,BAHT", font_C12B, "NO", "CENTER", "MIDDLE", 1, 1));
      if(screen.getString("MCANDIDATE","SALARY_EXPECT").length() == 0){
        detail.addCell(getCellData("  ", font_C12N, "R_BOTTOM", "CENTER", "MIDDLE", 1, 1));
      }
      else{
      String Salary_Expect = screen.getString("MCANDIDATE","SALARY_EXPECT").replaceAll(",","");
      detail.addCell(getCellData(DFO.format(Integer.valueOf(Salary_Expect)).toString(), font_C12N, "R_BOTTOM", "CENTER", "TOP", 1, 1,true,false));
      } 
      detail.addCell(getCellData("PER MONTH", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
       setPaddingTop(10.5f);
       setPaddingBottom(0.5f);
      detail.addCell(getCellData(" ", font_C12B, "NO", "CENTER", "MIDDLE", 5, 1));
      document.add(detail);

      // --------------- new line -----------------
      sizeColumn = new float[]{100.0f};
      detail = new PdfPTable(1);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(0.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(0.5f);
      detail.addCell(getCellData("PERSONAL DATA", font_C18B, "", "CENTER", "MIDDLE", 1, 1, false,false));
      document.add(detail);

      // --------------- new line -----------------
      sizeColumn = new float[]{10.0f,40.0f,5.0f,10.0f,5.0f};
      detail = new PdfPTable(5);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(5.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("NAME IN ENGLISH", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(prefixDescEN+simmcandidatewithgson.mcandidatePersonal.fname.eng+"   "+simmcandidatewithgson.mcandidatePersonal.lname.eng, font_C12N, "R_BOTTOM", "CENTER", "MIDDLE", 1, 1, false,false));
      detail.addCell(getCellData("AGE", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(age_memployee.substring(0,2), font_C12N, "R_BOTTOM", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("YEARS", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));

      detail.addCell(getCellData("NAME IN THAI", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(prefixDescTH+simmcandidatewithgson.mcandidatePersonal.fname.tha+"   "+simmcandidatewithgson.mcandidatePersonal.lname.tha, font_C12N, "R_BOTTOM", "CENTER", "MIDDLE", 1, 1, false,false));
      detail.addCell(getCellData(".", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(" ", font_C12B, "NO", "LEFT", "MIDDLE", 2, 1));

      document.add(detail);

      // --------------- new line -----------------
      sizeColumn = new float[]{11.0f,20.0f,11.0f,20.0f,10.0f,12.0f};
      detail = new PdfPTable(6);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(5.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("DATE OF BIRTH", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(langthai? new CscCalendar(simmcandidatewithgson.mcandidatePersonal.birthdate.substring(0, 10)).getDDMMYYYY().replaceAll("-","/")
        : new CscCalendar(simmcandidatewithgson.mcandidatePersonal.birthdate.substring(0, 10)).getDDMMYYYY().replaceAll("-","/"), font_C12N, "R_BOTTOM", "CENTER", "TOP", 1, 1,true,false));
      detail.addCell(getCellData("PLACE OF BIRTH", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(simmcandidatewithgson.mcandidatePersonal.birthplace, font_C12N, "R_BOTTOM", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("NATIONALITY", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(nationadesc, font_C12N, "R_BOTTOM", "CENTER", "MIDDLE", 1, 1));
      document.add(detail); 

      // --------------- new line -----------------
      String personal_status = simmcandidatewithgson.mcandidatePersonal.status;
      //S โสด M สมรส D หย่า W หม้าย E แยกกันอยู่
      if(personal_status.equalsIgnoreCase("S")){
        if (langthai) { personal_status = "โสด" ;}else{   personal_status="Single";}
      }else if(personal_status.equalsIgnoreCase("M")){
        if (langthai) { personal_status = "สมรส" ;}else{   personal_status="Marry";}
      }else if(personal_status.equalsIgnoreCase("D")){
        if (langthai) { personal_status = "หย่า" ;}else{   personal_status="Divorce";}
      }else if(personal_status.equalsIgnoreCase("W")){
        if (langthai) { personal_status = "หม้าย" ;}else{   personal_status="Widow";}
      }else if(personal_status.equalsIgnoreCase("E")){
        if (langthai) { personal_status = "แยกกันอยู่" ;}else{   personal_status="Separated";}
      }
      sizeColumn = new float[]{5.0f,18.0f,10.0f,18.0f,12.0f,6.0f};
      detail = new PdfPTable(6);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(5.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("SEX", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData( gender , font_C12N, "R_BOTTOM", "LEFT", "MIDDLE", 1, 1));

      detail.addCell(getCellData("MARITAL STATUS", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(personal_status, font_C12N, "R_BOTTOM", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("NUMBER OF CHILDREN", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData((Integer.valueOf(childtotal)).toString(), font_C12N, "R_BOTTOM", "CENTER", "MIDDLE", 1, 1));
      document.add(detail); 

      // --------------- new line -----------------
      String AddressCurrent = "เลขที่ " + simmcandidatewithgson.mcandidateContact.current.addr +" " ;
      AddressCurrent += simmcandidatewithgson.mcandidateContact.current.village +" "  ;
      AddressCurrent += "ห้องเลขที่ " + simmcandidatewithgson.mcandidateContact.current.roomNo +" "  ;
      AddressCurrent += "ชั้น " + simmcandidatewithgson.mcandidateContact.current.floor +" "  ;
      AddressCurrent += "ซ." + simmcandidatewithgson.mcandidateContact.current.soi +" "  ;
      AddressCurrent += "หมู่ " + simmcandidatewithgson.mcandidateContact.current.moo +" "  ;
      AddressCurrent += "ถนน " + simmcandidatewithgson.mcandidateContact.current.road +" "  ;
      AddressCurrent += simmcandidatewithgson.mcandidateContact.current.district +" "  ;
      AddressCurrent += simmcandidatewithgson.mcandidateContact.current.zipcode.disname.tha +" "  ;
      AddressCurrent += simmcandidatewithgson.mcandidateContact.current.zipcode.proname.tha +" "  ;
      AddressCurrent += simmcandidatewithgson.mcandidateContact.current.zipcode.zipid +" "  ;
      //AddressCurrent += AddressCurrent.length(); ถ้าเกิน 130 ควรขึ้นบรรทัดใหม่

      sizeColumn = new float[]{10.0f,50.0f,5.0f,35.0f};
      detail = new PdfPTable(4);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(5.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("ADDRESS", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(AddressCurrent, font_C12N, "R_BOTTOM", "LEFT", "MIDDLE", 3, 1));

      detail.addCell(getCellData(" ", font_C12B, "R_BOTTOM", "LEFT", "MIDDLE", 2, 1));
      detail.addCell(getCellData("TEL :", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(simmcandidatewithgson.mcandidateContact.phone, font_C12N, "R_BOTTOM", "LEFT", "MIDDLE", 1, 1));

      document.add(detail); 

      // --------------- new line -----------------
      String IDnumber =simmcandidatewithgson.mcandidatePersonal.identification.iden_number;
      IDnumber = IDnumber.substring(0,1)+"-"+IDnumber.substring(1,5)+"-"+IDnumber.substring(5,10)+"-"+IDnumber.substring(10,12)+"-"+IDnumber.substring(12,13);
      sizeColumn = new float[]{22.0f,18.0f,10.0f,15.0f,10.0f,15.0f};
      detail = new PdfPTable(6);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(5.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("TELEPHONE NUMBER OF OFFICE", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(" ", font_C12B, "R_BOTTOM", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData("I.D CARD NO", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(IDnumber, font_C12N, "R_BOTTOM", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData("DATE ISSUED", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(new CscCalendar(simmcandidatewithgson.mcandidatePersonal.identification.pinstart.substring(0, 10)).getThaiDDMMYYYY().replaceAll("-","/"), font_C12N, "R_BOTTOM", "LEFT", "MIDDLE", 1, 1));

      document.add(detail); 
      // --------------- new line -----------------
      sizeColumn = new float[]{10.0f,25.0f,15.0f,15.0f,18.0f,15.0f};
      detail = new PdfPTable(6);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(5.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("ISSUED AT", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(simmcandidatewithgson.mcandidatePersonal.identification.issue_amp+" "+simmcandidatewithgson.mcandidatePersonal.identification.issue_proid, font_C12N, "R_BOTTOM", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData("TAX PAYER I.D NO", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(" ", font_C12B, "R_BOTTOM", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData("SOCiAL SECURITY NO", font_C12B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(" ", font_C12B, "R_BOTTOM", "LEFT", "MIDDLE", 1, 1));

      document.add(detail); 
      // --------------- new line -----------------
      sizeColumn = new float[]{100.0f};
      detail = new PdfPTable(1);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(0.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(0.5f);
      detail.addCell(getCellData(" ", font_C18B, "NO", "CENTER", "MIDDLE", 1, 1, false,false));
      detail.addCell(getCellData("EDUCATION HISTORY", font_C18B, "", "CENTER", "MIDDLE", 1, 1, false,false));
      document.add(detail);
      // --------------- new line -----------------
      sizeColumn = new float[]{15.0f,25.0f,8.0f,5.0f,15.0f,25.0f};
      detail = new PdfPTable(6);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(3.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("LEVEL", font_C12B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("NAME OF \nINSTITUTION", font_C12B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("FROM", font_C12B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("TO", font_C12B, "R_BOTTOM", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("DIPLOMA/DEGREE", font_C12B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("DETAIL (MAJOR/HONOUR/ETC)", font_C12B, "", "CENTER", "MIDDLE", 1, 1));

      detail.addCell(getCellData("MASTER", font_C12B, "", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(langthai? educationbackground.get("nameth2").toString() : educationbackground.get("nameen2").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("from2").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("to2").toString(), font_C12N, "R_BOTTOM", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("gpa2").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(langthai? educationbackground.get("majorth2").toString() : educationbackground.get("majoren2").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));

      detail.addCell(getCellData("BACHELOR", font_C12B, "", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(langthai? educationbackground.get("nameth3").toString() : educationbackground.get("nameen3").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("from3").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("to3").toString(), font_C12N, "R_BOTTOM", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("gpa3").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(langthai? educationbackground.get("majorth3").toString() : educationbackground.get("majoren3").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));

      detail.addCell(getCellData("DIPLOMA", font_C12B, "", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(langthai? educationbackground.get("nameth4").toString() : educationbackground.get("nameen4").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("from4").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("to4").toString(), font_C12N, "R_BOTTOM", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("gpa4").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(langthai? educationbackground.get("majorth4").toString() : educationbackground.get("majoren4").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));

      detail.addCell(getCellData("VOCATIONAL SCHOOL", font_C12B, "", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(langthai? educationbackground.get("nameth7").toString() : educationbackground.get("nameen7").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("from7").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("to7").toString(), font_C12N, "R_BOTTOM", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("gpa7").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(langthai? educationbackground.get("majorth7").toString() : educationbackground.get("majoren7").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));

      detail.addCell(getCellData("SECONDARY SCHOOL", font_C12B, "", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(langthai? educationbackground.get("nameth8").toString() : educationbackground.get("nameen8").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("from8").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("to8").toString(), font_C12N, "R_BOTTOM", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("gpa8").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(langthai? educationbackground.get("majorth8").toString() : educationbackground.get("majoren8").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));

      detail.addCell(getCellData("OTHER", font_C12B, "", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(langthai? educationbackground.get("nameth12").toString() : educationbackground.get("nameen12").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("from12").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("to12").toString(), font_C12N, "R_BOTTOM", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(educationbackground.get("gpa12").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(langthai? educationbackground.get("majorth12").toString() : educationbackground.get("majoren12").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));

      document.add(detail); 
      // --------------- new line -----------------
      sizeColumn = new float[]{100.0f};
      detail = new PdfPTable(1);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(0.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(0.5f);
      detail.addCell(getCellData("TRAINING", font_C18B, "", "CENTER", "MIDDLE", 1, 1, false,false));
      document.add(detail);
      // --------------- new line -----------------
      String jobtraining0 =jobexp_training.get("start0").toString()+" - "+jobexp_training.get("end0").toString();
      String jobname0 =   jobexp_training.get("name0").toString();
      if(jobname0.equalsIgnoreCase("")){
        jobtraining0 = "-";
      }

      sizeColumn = new float[]{20.0f,40.0f,40.0f};
      detail = new PdfPTable(3);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(3.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("YEAR\nMONTH/YEAR", font_C12B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("NAME OF INSTITUTION", font_C12B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("COURSES / DETAILS", font_C12B, "", "CENTER", "MIDDLE", 1, 1));

      detail.addCell(getCellData(jobtraining0, font_C12N, "", "CENTER", "TOP", 1, 1, false,false));
      detail.addCell(getCellData(jobexp_training.get("by0").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(jobexp_training.get("name0").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));

      detail.addCell(getCellData(jobexp_training.get("start1").toString()+" - "+jobexp_training.get("end1").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, false,false));
      detail.addCell(getCellData(jobexp_training.get("by1").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(jobexp_training.get("name1").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));

      detail.addCell(getCellData(jobexp_training.get("start2").toString()+" - "+jobexp_training.get("end2").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, false,false));
      detail.addCell(getCellData(jobexp_training.get("by2").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(jobexp_training.get("name2").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));

      detail.addCell(getCellData(jobexp_training.get("start3").toString()+" - "+jobexp_training.get("end3").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, false,false));
      detail.addCell(getCellData(jobexp_training.get("by3").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(jobexp_training.get("name3").toString(), font_C12N, "", "CENTER", "TOP", 1, 1, true,false));
      document.add(detail); 


      // --------------- new line PAGE 2-----------------
      document.newPage();


      sizeColumn = new float[]{50.0f,50.0f};
      detail = new PdfPTable(2);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(0.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(0.5f);
      detail.addCell(cellDetailHeader);      
      detail.addCell(getCellData2( content, "NO", "RIGHT", "MIDDLE",  1,  1) );
      detail.addCell(getCellData(" ", font_C12B, "NO", "RIGHT", "MIDDLE", 2, 1));
      document.add(detail);

      // --------------- new line -----------------
      String jobstart0 =  jobexp.get("start0").toString();
      String present0 =  jobexp.get("present0").toString().equalsIgnoreCase("true")?"ปัจจุบัน":" "+jobexp.get("end0").toString();
      String chkjobexp0 = jobexp.get("companyname_job0").toString();
      if(chkjobexp0.equalsIgnoreCase("")){
        jobstart0 = " ";
        present0 = " ";
      }

      sizeColumn = new float[]{10.0f,7.0f,7.0f,20.0f,5.0f,5.0f,10.0f,10.0f,10.0f};
      detail = new PdfPTable(9);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(3.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("EMPLOYMENT HISTORY (STARTING WITH CURRENT POSITION", font_C12B, "", "CENTER", "MIDDLE", 9, 1));
      detail.addCell(getCellData("COMPANY\nNAME", font_C12B, "", "CENTER", "MIDDLE", 1, 2));
      detail.addCell(getCellData("FROM", font_C12B, "", "CENTER", "MIDDLE", 1, 2));
      detail.addCell(getCellData("TO", font_C12B, "", "CENTER", "MIDDLE", 1, 2));
      detail.addCell(getCellData("ADDRESS", font_C12B, "", "CENTER", "MIDDLE", 1, 2));
      detail.addCell(getCellData("SAlARY", font_C12B, "", "CENTER", "MIDDLE", 2, 1));
      detail.addCell(getCellData("POSITION", font_C12B, "", "CENTER", "MIDDLE", 1, 2));
      detail.addCell(getCellData("DUTIES", font_C12B, "", "CENTER", "MIDDLE", 1, 2));
      detail.addCell(getCellData("REASON FOR\nLEAVING", font_C12B, "", "CENTER", "MIDDLE", 1, 2));
      detail.addCell(getCellData("START", font_C12B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("END", font_C12B, "", "CENTER", "MIDDLE", 1, 1));
      setPaddingTop(10.5f);
      setPaddingBottom(10.5f);
      detail.addCell(getCellData(" "+jobexp.get("companyname_job0").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(" "+jobexp.get("start0").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(" "+present0, font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(chk.chkNullString( AddressJob[0]," "), font_C10N, "", "CENTER", "TOP", 1, 1, false,false));
      detail.addCell(getCellData(" "+jobexp.get("salary0").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(" "+jobexp.get("endingsalary0").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(" "+jobexp.get("title0").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, false,false));
      detail.addCell(getCellData(" "+jobexp.get("title0").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(" "+jobexp.get("reason0").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, true,false));

      detail.addCell(getCellData(" "+jobexp.get("companyname_job1").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(" "+jobexp.get("start1").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(" "+jobexp.get("present1").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(chk.chkNullString( AddressJob[1]," "), font_C10N, "", "CENTER", "TOP", 1, 1, false,false));
      detail.addCell(getCellData(" "+jobexp.get("salary1").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(" "+jobexp.get("endingsalary1").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(" "+jobexp.get("title1").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, false,false));
      detail.addCell(getCellData(" "+jobexp.get("title1").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(" "+jobexp.get("reason1").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, true,false));

      detail.addCell(getCellData(" "+jobexp.get("companyname_job2").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(" "+jobexp.get("start2").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(" "+jobexp.get("present2").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(chk.chkNullString( AddressJob[2]," "), font_C10N, "", "CENTER", "TOP", 1, 1, false,false));
      detail.addCell(getCellData(" "+jobexp.get("salary2").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(" "+jobexp.get("endingsalary2").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(" "+jobexp.get("title2").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, false,false));
      detail.addCell(getCellData(" "+jobexp.get("title2").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(" "+jobexp.get("reason2").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, true,false));

      detail.addCell(getCellData(" "+jobexp.get("companyname_job3").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(" "+jobexp.get("start3").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(" "+jobexp.get("present3").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(chk.chkNullString( AddressJob[3]," "), font_C10N, "", "CENTER", "TOP", 1, 1, false,false));
      detail.addCell(getCellData(" "+jobexp.get("salary3").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(" "+jobexp.get("endingsalary3").toString(), font_C10N, "", "CENTER", "TOP", 1, 1));
      detail.addCell(getCellData(" "+jobexp.get("title3").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, false,false));
      detail.addCell(getCellData(" "+jobexp.get("title3").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, true,false));
      detail.addCell(getCellData(" "+jobexp.get("reason3").toString(), font_C10N, "", "CENTER", "TOP", 1, 1, true,false));

      document.add(detail); 
     // --------------- new line -----------------
      String description = jobexp.get("description0").toString();
      sizeColumn = new float[]{100.0f};
      detail = new PdfPTable(1);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(3.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("PLEASE COMPLETE ORGANIZATION CHART SHOWING YOUR POSITION IN YOUR PRESENT EMPLOYMENT.", font_C13B, "", "LEFT", "MIDDLE", 1, 1, false,false));
      setPaddingBottom(300.5f);
      detail.addCell(getCellData(description, font_C12N, "", "LEFT", "MIDDLE", 1, 1, false,false));
      

      document.add(detail);
 
      // --------------- new line PAGE 3-----------------
      document.newPage();

      sizeColumn = new float[]{50.0f,50.0f};
      detail = new PdfPTable(2);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(0.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(0.5f);
      detail.addCell(cellDetailHeader);      
      detail.addCell(getCellData2( content, "NO", "RIGHT", "MIDDLE",  1,  1) );
      detail.addCell(getCellData(" ", font_C12B, "NO", "RIGHT", "MIDDLE", 2, 1));
      document.add(detail);
      // --------------- new line -----------------

      sizeColumn = new float[]{40.0f,15.0f,15.0f,15.0f,15.0f};
      detail = new PdfPTable(5);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(3.0f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("GENERAL INFORMATION", font_C18B, " ", "CENTER","MIDDLE", 6, 1));
      detail.addCell(getCellData("FOREIGN LANGUAGE", font_C13B, " ", "CENTER","MIDDLE", 1, 1));
      detail.addCell(getCellData("SPEAKING", font_C13B, " ", "CENTER","MIDDLE", 1, 1));
      detail.addCell(getCellData("READING", font_C13B, " ", "CENTER","MIDDLE", 1, 1));
      detail.addCell(getCellData("WRITING", font_C13B, " ", "CENTER","MIDDLE", 1, 1));
      detail.addCell(getCellData("UNDERSTANDING", font_C13B, " ", "CENTER","MIDDLE", 1, 1));
      setPaddingBottom(30.5f);
      detail.addCell(getCellData(langthai? hmlangskill.get("skillNameTdesc0").toString() : hmlangskill.get("skillNameEdesc0").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));
      detail.addCell(getCellData(hmlangskill.get("speak0").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));
      detail.addCell(getCellData(hmlangskill.get("reading0").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));
      detail.addCell(getCellData(hmlangskill.get("write0").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));
      detail.addCell(getCellData(hmlangskill.get("listen0").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));

      detail.addCell(getCellData(langthai? hmlangskill.get("skillNameTdesc1").toString() : hmlangskill.get("skillNameEdesc1").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));
      detail.addCell(getCellData(hmlangskill.get("speak1").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));
      detail.addCell(getCellData(hmlangskill.get("reading1").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));
      detail.addCell(getCellData(hmlangskill.get("write1").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));
      detail.addCell(getCellData(hmlangskill.get("listen1").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));

      detail.addCell(getCellData(hmlangskill.get("skillNameTdesc2").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));
      detail.addCell(getCellData(hmlangskill.get("speak2").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));
      detail.addCell(getCellData(hmlangskill.get("reading2").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));
      detail.addCell(getCellData(hmlangskill.get("write2").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));
      detail.addCell(getCellData(hmlangskill.get("listen2").toString(), font_C12N, " ", "CENTER","MIDDLE", 1, 1,false,false));
      document.add(detail);
      // --------------- new line -----------------
      sizeColumn = new float[]{22.0f,30.0f,48.0f};
      detail = new PdfPTable(3);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(3.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(0.5f);
      detail.addCell(getCellData("DATE AVAILABILTY", font_C18B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(" ", font_C18B, "R_BOTTOM", "CENTER", "MIDDLE", 1, 1, false,false));
      detail.addCell(getCellData(" ", font_C18B, "NO", "CENTER", "MIDDLE", 1, 1, false,false));
      detail.addCell(getCellData(" ", font_C18B, "NO", "CENTER", "MIDDLE", 3, 1));

      document.add(detail);

      // --------------- new line -----------------
      sizeColumn = new float[]{100.0f};
      detail = new PdfPTable(1);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(3.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(0.5f);
      detail.addCell(getCellData("REFERENCES", font_C18B, "", "CENTER", "MIDDLE", 1, 1, false,false));
      detail.addCell(getCellData("BUSINESS", font_C18B, "", "LEFT", "MIDDLE", 1, 1, false,false));
      document.add(detail);

      // --------------- new line -----------------
      String jobtitle0 = familyreference.get("jobtitle0").toString();
      String jobtitle1 = familyreference.get("jobtitle1").toString();
      String jobtitle2 = familyreference.get("jobtitle2").toString();
      String companyname0 = familyreference.get("companyname0").toString();
      String companyname1 = familyreference.get("companyname1").toString();
      String companyname2 = familyreference.get("companyname2").toString();

      sizeColumn = new float[]{15.0f,30.0f,25.0f,30.0f};
      detail = new PdfPTable(4);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(10.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("NAME", font_C18B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("NAME OF COMPANY", font_C18B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("POSITION", font_C18B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("ADDRESS / TELEPHONE NO.", font_C18B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData(companyname0.equalsIgnoreCase("")? " " : "1. "+familyreference.get("name0").toString(), font_C12N, "", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(companyname0, font_C12N, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData(jobtitle0, font_C12N, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData(familyreference.get("address0").toString()+" / "+familyreference.get("phone0").toString(), font_C12N, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData(companyname1.equalsIgnoreCase("")? " " : "2. "+familyreference.get("name1").toString(), font_C12N, "", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(companyname1, font_C12N, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData(jobtitle1, font_C12N, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData(familyreference.get("address1").toString()+" / "+familyreference.get("phone1").toString(), font_C12N, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData(companyname2.equalsIgnoreCase("")? " " : "3. "+familyreference.get("name2").toString(), font_C12N, "", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(companyname2, font_C12N, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData(jobtitle2, font_C12N, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData(companyname2.equalsIgnoreCase("")? " " : "NONE"+" / "+familyreference.get("phone2").toString(), font_C12N, "", "CENTER", "MIDDLE", 1, 1));

      document.add(detail);

      // --------------- new line -----------------
      String Emergencyname = simmcandidatewithgson.mcandidateContact.emergencyContact.name;
      sizeColumn = new float[]{20.0f,40.0f,20.0f,20.0f};
      detail = new PdfPTable(4);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(10.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("PERSONAL", font_C18B, "", "LEFT", "MIDDLE", 4, 1));
      detail.addCell(getCellData("NAME", font_C18B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("HOME AND/OR BUSINESS ADDRESS", font_C18B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("RELATIONSHIP", font_C18B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("TELEPHONE NO.", font_C18B, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData(Emergencyname.equalsIgnoreCase("")? " " : "1."+simmcandidatewithgson.mcandidateContact.emergencyContact.name, font_C12N, "", "LEFT", "TOP", 1, 1,true,false));
      detail.addCell(getCellData(simmcandidatewithgson.mcandidateContact.emergencyContact.address, font_C12N, "", "CENTER", "TOP", 1, 1,true,false));
      detail.addCell(getCellData(simmcandidatewithgson.mcandidateContact.emergencyContact.relations, font_C12N, "", "CENTER", "TOP", 1, 1,true,false));
            String PhoneF = simmcandidatewithgson.mcandidateContact.emergencyContact.phone;
      if(PhoneF.length() == 10){
        PhoneF = PhoneF.substring(0,3)+"-"+PhoneF.substring(3,6)+"-"+PhoneF.substring(6,10);
      }
      else if((PhoneF.length() == 9)){
        PhoneF = PhoneF.substring(0,2)+"-"+PhoneF.substring(2,5)+"-"+PhoneF.substring(5,9);
      }
      detail.addCell(getCellData(PhoneF, font_C12N, "", "CENTER", "TOP", 1, 1));

      detail.addCell(getCellData(" ", font_C12N, "", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(" ", font_C12N, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData(" ", font_C12N, "", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData(" ", font_C12N, "", "CENTER", "MIDDLE", 1, 1));
      document.add(detail);

      // --------------- new line -----------------
      sizeColumn = new float[]{100.0f};
      detail = new PdfPTable(1);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(10.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(0.5f);
      content = new Phrase();
      content.add(new Chunk("I WARRANT THAT ALL FACTS AND STATEMENTS GIVEN IN THIS APPLICATION ARE,TO THE BEST OF MY KNOWLEDGE,TRUE AND\n",font_C13B));
      content.add(new Chunk("THAT NOTHING MATERIAL HAS BEEN OMITTED",font_C13B));
      detail.addCell(getCellData2( content, "NO", "LEFT", "MIDDLE",  1,  1) );
      setPaddingTop(3.5f);

      content = new Phrase();
      content.add(new Chunk("I ACKNOWLEDGE THAT ANY OFFER OF EMPLOYMENT WHICH MAY BE MADE TO ME WILL BE MADE IN RELIANCE ON THESE FACETS\n",font_C13B));
      content.add(new Chunk("AND STATEMENTS. I ACCEPT THAT FALSE OR INACCURATE INFORMATION MAY RESULT IN THE TERMINATE OF MU EMPOLOYMENT. I \n",font_C13B));
      content.add(new Chunk("KNOW THAT ANY OFFER EMPLOMENT WILL BE CONDITIONAL UPON MY ACCEPTANCE OF DATA GENERAL'S STANDARD TERMS.",font_C13B));
      detail.addCell(getCellData2( content, "NO", "LEFT", "MIDDLE",  1,  1) );
      document.add(detail);

      // --------------- new line -----------------
      sizeColumn = new float[]{18.0f,40.0f,5.0f,20.0f};
      detail = new PdfPTable(4);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(60.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      detail.addCell(getCellData("SIGNATURE OF CANDIDATE", font_C13B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(" ", font_C13B, "R_BOTTOM", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData("DATE", font_C13B, "NO", "LEFT", "MIDDLE", 1, 1));
      detail.addCell(getCellData(" ", font_C13B, "R_BOTTOM", "CENTER", "MIDDLE", 1, 1));
      setPaddingTop(0.5f);
      document.add(detail);
      // -----------------------------------------------------------------------------
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        document.close();
      }
    }
 
    if (hasData) {
      OutputStream os = response.getOutputStream();
    // Create a reader
      PdfReader reader = new PdfReader(baos.toByteArray());
    // Create a stamper
      PdfStamper stamper = new PdfStamper(reader, baos);

    // Close the stamper
      stamper.close();
      reader.close();

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

    // setting the content type
      response.setContentType("application/pdf");
    // the contentlength
      response.setContentLength(baos.size());
    // write ByteArrayOutputStream to the ServletOutputStream

      baos.writeTo(os);

      os.flush();
      os.close(); 
    }
    //PdfWriter.getInstance(document, baos);
    %>

    <%!
    Float padding = 0.0f;
    Float paddingtop = 0.0f;
    Float paddingbottom = 0.0f;
    Float paddingleft = 0.0f;
    Float paddingright = 0.0f;
    BaseColor basecolor = new BaseColor(0, 0, 0);

    private PdfPCell getCellData(String text, Font font, String noborder, String horalign, String veralign, int colspan, int rowspan) {
      return getCellData(text, font, noborder, horalign, veralign, colspan, rowspan, false,false);
    }
   
    //get call data
    private PdfPCell getCellData(String text, Font font, String noborder, String horalign, String veralign, int colspan, int rowspan,boolean setheight, boolean bgcolor) {
      PdfPCell cellDetail = new PdfPCell(new Phrase(text, font));
      cellDetail.setNoWrap(false);
    //  cellDetail.setNoWrap(true);

      if (horalign.equalsIgnoreCase("LEFT")) {
        cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
      } else if (horalign.equalsIgnoreCase("CENTER")) {
        cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
      } else if (horalign.equalsIgnoreCase("RIGHT")) {
        cellDetail.setHorizontalAlignment(Element.ALIGN_RIGHT);
      }

      if (veralign.equalsIgnoreCase("TOP")) {
        cellDetail.setVerticalAlignment(Element.ALIGN_TOP);
      } else if (veralign.equalsIgnoreCase("MIDDLE")) {
        cellDetail.setVerticalAlignment(Element.ALIGN_MIDDLE);
      } else if (veralign.equalsIgnoreCase("BOTTOM")) {
        cellDetail.setVerticalAlignment(Element.ALIGN_BOTTOM);
      }

      if (padding > 0.0f) {
        cellDetail.setPadding(padding);
      }
      if (paddingtop > 0.0f) {
        cellDetail.setPaddingTop(paddingtop);
      }
      if (paddingbottom > 0.0f) {
        cellDetail.setPaddingBottom(paddingbottom);
      }
      if (paddingleft > 0.0f) {
        cellDetail.setPaddingLeft(paddingleft);
      }
      if (paddingright > 0.0f) {
        cellDetail.setPaddingRight(paddingright);
      }
      if (colspan > 0) {
        cellDetail.setColspan(colspan);
      }
      if (rowspan > 0) {
        cellDetail.setRowspan(rowspan);
      }

      if (noborder.equalsIgnoreCase("NO")) {
        cellDetail.setBorder(Rectangle.NO_BORDER);
      }
      else if(noborder.equalsIgnoreCase("R_TR")){ 
            cellDetail.setBorder(Rectangle.TOP | Rectangle.RIGHT);
      } 
      else if(noborder.equalsIgnoreCase("R_LR")){ 
            cellDetail.setBorder(Rectangle.LEFT | Rectangle.RIGHT);
      } 
      else if(noborder.equalsIgnoreCase("R_RB")){ 
            cellDetail.setBorder(Rectangle.RIGHT | Rectangle.BOTTOM);
      } 
      else if(noborder.equalsIgnoreCase("R_TB")){ 
            cellDetail.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
      } 
      else if(noborder.equalsIgnoreCase("R_TLR")){ 
            cellDetail.setBorder(Rectangle.TOP | Rectangle.LEFT | Rectangle.RIGHT);
      } 
      else if(noborder.equalsIgnoreCase("R_LRB")){ 
            cellDetail.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
      } 
       else if(noborder.equalsIgnoreCase("R_TLB")){ 
            cellDetail.setBorder(Rectangle.TOP | Rectangle.LEFT | Rectangle.BOTTOM);
      } 
      else if(noborder.equalsIgnoreCase("R_TRB")){ 
            cellDetail.setBorder(Rectangle.TOP | Rectangle.RIGHT | Rectangle.BOTTOM);
      } 
      else if(noborder.equalsIgnoreCase("R_BOTTOM")){ 
            cellDetail.setBorder(Rectangle.BOTTOM);
      }
      else if(noborder.equalsIgnoreCase("R_RIGHT")){ 
            cellDetail.setBorder(Rectangle.RIGHT);
      }
    
      else{

      }
      if (bgcolor) {
        cellDetail.setBackgroundColor(basecolor);
      } 
      if (setheight) {
        cellDetail.setFixedHeight(0.6999512f);
      } 
      return cellDetail;
    }


    //CellDeatail2 Use For Add Chunk(1row 2 Fonts Or Color)
    private PdfPCell getCellData2(Phrase content, String noborder, String horalign, String veralign, int colspan, int rowspan) {
      return getCellData2(content, noborder, horalign, veralign, colspan, rowspan, false,false);
    }
    private PdfPCell getCellData2(Phrase content, String noborder, String horalign, String veralign, int colspan, int rowspan,boolean setheight, boolean bgcolor) {
      PdfPCell cellDetail2 = new PdfPCell(new Phrase(content));
        cellDetail2.setNoWrap(false);
      if (horalign.equalsIgnoreCase("LEFT")) {
        cellDetail2.setHorizontalAlignment(Element.ALIGN_LEFT);
      } else if (horalign.equalsIgnoreCase("CENTER")) {
        cellDetail2.setHorizontalAlignment(Element.ALIGN_CENTER);
      } else if (horalign.equalsIgnoreCase("RIGHT")) {
        cellDetail2.setHorizontalAlignment(Element.ALIGN_RIGHT);
      }

      if (veralign.equalsIgnoreCase("TOP")) {
        cellDetail2.setVerticalAlignment(Element.ALIGN_TOP);
      } else if (veralign.equalsIgnoreCase("MIDDLE")) {
        cellDetail2.setVerticalAlignment(Element.ALIGN_MIDDLE);
      } else if (veralign.equalsIgnoreCase("BOTTOM")) {
        cellDetail2.setVerticalAlignment(Element.ALIGN_BOTTOM);
      }

      if (padding > 0.0f) {
        cellDetail2.setPadding(padding);
      }
      if (paddingtop > 0.0f) {
        cellDetail2.setPaddingTop(paddingtop);
      }
      if (paddingbottom > 0.0f) {
        cellDetail2.setPaddingBottom(paddingbottom);
      }
      if (paddingleft > 0.0f) {
        cellDetail2.setPaddingLeft(paddingleft);
      }
      if (paddingright > 0.0f) {
        cellDetail2.setPaddingRight(paddingright);
      }
      if (colspan > 0) {
        cellDetail2.setColspan(colspan);
      }
      if (rowspan > 0) {
        cellDetail2.setRowspan(rowspan);
      }

      if (noborder.equalsIgnoreCase("NO")) {
        cellDetail2.setBorder(Rectangle.NO_BORDER);
      }
      else if(noborder.equalsIgnoreCase("R_TR")){ 
            cellDetail2.setBorder(Rectangle.TOP | Rectangle.RIGHT);
      } 
      else if(noborder.equalsIgnoreCase("R_LR")){ 
            cellDetail2.setBorder(Rectangle.LEFT | Rectangle.RIGHT);
      } 
       else if(noborder.equalsIgnoreCase("R_RB")){ 
            cellDetail2.setBorder(Rectangle.RIGHT | Rectangle.BOTTOM);
      } 
      else if(noborder.equalsIgnoreCase("R_TB")){ 
            cellDetail2.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
      } 
      else if(noborder.equalsIgnoreCase("R_TLR")){ 
            cellDetail2.setBorder(Rectangle.TOP | Rectangle.LEFT | Rectangle.RIGHT);
      } 
      else if(noborder.equalsIgnoreCase("R_LRB")){ 
            cellDetail2.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
      } 
       else if(noborder.equalsIgnoreCase("R_TLB")){ 
            cellDetail2.setBorder(Rectangle.TOP | Rectangle.LEFT | Rectangle.BOTTOM);
      } 
      else if(noborder.equalsIgnoreCase("R_TRB")){ 
            cellDetail2.setBorder(Rectangle.TOP | Rectangle.RIGHT | Rectangle.BOTTOM);
      } 
      else if(noborder.equalsIgnoreCase("R_BOTTOM")){ 
            cellDetail2.setBorder(Rectangle.BOTTOM);
      }

      if (bgcolor) {
        cellDetail2.setBackgroundColor(basecolor);
      }
      if (setheight) {
        cellDetail2.setFixedHeight(0.6999512f);
      } 
      return cellDetail2;
    }
    
    private void setPadding(Float padding) {
      this.padding = padding;
    }

    private void setPaddingTop(Float padding) {
      this.paddingtop = padding;
    }

    private void setPaddingBottom(Float padding) {
      this.paddingbottom = padding;
    }

    private void setPaddingLeft(Float padding) {
      this.paddingleft = padding;
    }

    private void setPaddingRight(Float padding) {
      this.paddingright = padding;
    }

    private void setBaseBackgroundColor(int r, int g, int b) {
      this.basecolor = new BaseColor(r, g, b);
    }
   // Add IMAGE IN PART
    private String getImagePath(String type, String subFolder, String imageFileName, String defaultFile) {
      InitialEnvironment inv = new InitialEnvironment("GLOBAL");
      String path = inv.getValue(type)+subFolder;
      if (!new File(path+imageFileName).exists() || imageFileName.equals("")){
        imageFileName = defaultFile;
      }
      return path+imageFileName;
    }

  public class HeaderFooterPageEvent extends PdfPageEventHelper {
    public void onStartPage(PdfWriter writer, Document document) {
     //   ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("Top Left"), 30, 800, 0);
     //   ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("Top Right"), 550, 800, 0);
    }
    public void onEndPage(PdfWriter writer, Document document) {
        ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("QF-58-03"), 550, 30, 0);
        ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("ISSUE-B"), 550, 18, 0);
        ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(document.getPageNumber()+" OF 3"), 300, 30, 0);
    }

}

    %>
    </body>
    </html>