public void insertPdf(HttpServletRequest request, InterviewCandidateMaterial material) {
    // TODO Auto-generated method stub
    log.log(Level.INFO, "ApplicationFormPDFMaintenance --> insertPdf ");
    Session session = null;
    Transaction tx;
    try {
      session = HibernateFactory.openSession();
      tx = session.beginTransaction();
      ArrayList listData = null;
      Criteria criteria = session.createCriteria(InterviewCandidateMaterial.class);
      criteria.add(Restrictions.eq("candidateCode", material.getCandidateCode()));
      criteria.add(Restrictions.eq("interviewCode", material.getInterviewCode()));
      listData = (ArrayList) criteria.list();
      if (listData.size() == 0) {
        session.save(material);
        tx.commit();
      }

    } catch (Exception e) {
      log.log(Level.INFO, "ApplicationFormPDFMaintenance --> insertPdf " + 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());
    } finally {
      try {
        HibernateFactory.close(session);

      } catch (Exception e) {
        log.log(Level.INFO, "ApplicationFormPDFMaintenance --> insertPdf " + e.getMessage());
        e.printStackTrace();
        LogsMaintenance logsMain = new LogsMaintenance();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        logsMain.insertLogs("ApplicationFormPDFMaintenance", Level.SEVERE + "", errors.toString());
        e.printStackTrace();
      }
    }
  }
  public static InterviewCandidateMaterial pdf(
      HttpServletRequest request, AddressBook addressbook) {
    // TODO Auto-generated method stub
    log.log(Level.INFO, "ApplicationFormPDFMaintenance --> pdf ");
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    // Font myAdobeTypekit =
    // FontFactory.getFont(request.getRealPath(File.separator)+"resources"+File.separator+"HDZB_35.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

    try {
      // String fontPath = "C:/Windows/Fonts";

      String fontPath = request.getRealPath("/") + "resources" + File.separator + "hxb-meixinti";
      File f2 = new File(fontPath + "/hxb-meixinti.ttf");
      BaseFont bf1 = null;
      if (f2.exists()) {
        bf1 =
            BaseFont.createFont(
                fontPath + "/hxb-meixinti.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
      } else {
        f2 = new File(fontPath + "/hxb-meixinti.ttf");

        if (f2.exists()) {
          System.out.println("File existed");
          bf1 =
              BaseFont.createFont(
                  fontPath + "hxb-meixinti.ttf", BaseFont.IDENTITY_V, BaseFont.EMBEDDED);
        } else {
          bf1 =
              BaseFont.createFont(
                  FontManager.getFontPath(true) + "/hxb-meixinti.ttf",
                  BaseFont.IDENTITY_H,
                  BaseFont.EMBEDDED);
        }
      }

      Font normalFontCH = new Font(bf1, 15);

      String fileName =
          request.getRealPath("/") + "resources" + File.separator + "upload" + File.separator;
      DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
      Date d1 = new Date();
      String time = (d1.getTime() + "").trim();
      String str = df.format(new Date()) + time;

      PdfWriter writer =
          PdfWriter.getInstance(
              document, new FileOutputStream(fileName + "ApplicationForm_" + str + ".pdf"));
      InterviewCandidateMaterial material = new InterviewCandidateMaterial();
      material.setMaterialFileName("ApplicationForm_" + str + ".pdf");
      material.setCandidateCode(Integer.parseInt(request.getParameter("candidateCode")));
      material.setInterviewCode(Integer.parseInt(request.getParameter("interviewCode")));

      // PdfWriter writer = PdfWriter.getInstance(document, new
      // FileOutputStream("E://applicatonForm2.pdf"));
      document.open();

      addTitle(document, writer, "formHeaderTitle", "Application Form");
      document = personalInformation(document, writer, addressbook, normalFontCH);
      document = familyInformation(document, writer, addressbook);
      document = workExperience(document, writer, addressbook);
      document = Education(document, writer, addressbook);
      document = personalCertification(document, writer, addressbook);
      document = ESingnature(document, writer, addressbook);

      document.close();

      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      File file = new File(fileName + "ApplicationForm_" + str + ".pdf");
      FileInputStream fis = new FileInputStream(file);
      byte[] buf = new byte[1024];
      for (int readNum; (readNum = fis.read(buf)) != -1; ) {
        bos.write(buf, 0, readNum); // no doubt here is 0
      }
      material.setFormContent(bos.toByteArray());
      material.setCreatedDate(new Date());
      material.setMaterialDescrption("AppicationForm");

      //  applicationForm.setFormContent(bos.toByteArray());

      return material;
    } catch (Exception e) {
      log.log(Level.INFO, "ApplicationFormPDFMaintenance --> pdf --> Exception  " + 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 null;
  }