孔祥富
2021-03-08 4e52cb2253af9a22571c7d0c239ee283178d2fd4
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/util/CreatePdf.java
@@ -78,7 +78,7 @@
      }
   }
   int maxWidth = 842;
   int maxWidth = 800;
   /**
    * 为表格添加一个内容
@@ -138,35 +138,7 @@
      return cell;
   }
   /**
    * 为表格添加一个内容
    *
    * @param value
    *            值
    * @param font
    *            字体
    * @param align
    *            对齐方式
    * @param colspan
    *            占多少列
    * @param boderFlag
    *            是否有有边框
    * @return 添加的文本框
    */
   public PdfPCell createCell(String value, Font font, int align, int colspan, boolean boderFlag) {
      PdfPCell cell = new PdfPCell();
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      cell.setHorizontalAlignment(align);
      cell.setColspan(colspan);
      cell.setPhrase(new Phrase(value, font));
      cell.setPadding(3.0f);
      if (!boderFlag) {
         cell.setBorder(0);
         cell.setPaddingTop(15.0f);
         cell.setPaddingBottom(8.0f);
      }
      return cell;
   }
   /**
    * 创建一个表格对象
@@ -215,10 +187,44 @@
      Font fontChinese = new Font(bfChinese, 12, Font.NORMAL);
      return fontChinese;
   }
   /**
    * 为表格添加一个内容
    *
    * @param value
    *            值
    * @param font
    *            字体
    * @param align
    *            对齐方式
    * @param colspan
    *            占多少列
    * @param boderFlag
    *            是否有有边框
    * @return 添加的文本框
    */
   public PdfPCell createCell(String value, Font font, int align, int colspan, boolean boderFlag) {
      PdfPCell cell = new PdfPCell();
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      cell.setHorizontalAlignment(align);
      cell.setColspan(colspan);
      cell.setPhrase(new Phrase(value, font));
      cell.setPadding(3.0f);
      cell.setMinimumHeight(30);
      cell.setBorderColorBottom(BaseColor.BLACK);
      cell.setBorderColorLeft(BaseColor.BLACK);
      cell.setBorderColorRight(BaseColor.BLACK);
      cell.setBorderColorTop(BaseColor.BLACK);
      if (!boderFlag) {
         cell.setBorder(0);
         cell.setPaddingTop(15.0f);
         cell.setPaddingBottom(8.0f);
      }
      return cell;
   }
   public static void setTableStyle(PdfPTable table, PdfPCell cell) {
// 设置表格样式
      table.setLockedWidth(true);
      table.setTotalWidth(500);
      table.setTotalWidth(800);
      table.setHorizontalAlignment(Element.ALIGN_LEFT);
// 设置单元格样式
      cell.setMinimumHeight(35);
@@ -362,6 +368,38 @@
                  "员工手册",empBaseInfo.getHandbookStatusName()==null?"":empBaseInfo.getHandbookStatusName(),
                  "相关证件",empBaseInfo.getCertificateListName()==null?"":empBaseInfo.getCertificateListName()},
            {"身份证号码",empBaseInfo.getCertificateNumb()==null?"":empBaseInfo.getCertificateNumb()}};
      //生成三列表格
      PdfPTable table1 = new PdfPTable(1);
      PdfPCell cell1 = new PdfPCell();
      cell1.setBorderWidthTop(0);
      cell1.setBorderWidthRight(0);
      cell1.setBorderWidthBottom(0);
      cell1.setBorderWidthLeft(0);
      cell1.setUseAscender(true);
      cell1.setUseDescender(true);
      cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);//水平居中
      Paragraph para = null;
      try {
         para = new Paragraph(empBaseInfo.getEmpName()+"的档案", getPdfChineseFont());
      } catch (Exception e) {
         e.printStackTrace();
      }
      //设置该段落为居中显示
      cell1.setPhrase(para);
      table1.addCell(cell1);
//         每个cell的宽度
      float[] widthss = {400, 400, 400, 400,400, 400};
//          创建一个表格,每一行有四个cell
@@ -471,7 +509,6 @@
      for (int i = 0; i < remarkInfolength; i++) {
         remarkInfotable.addCell(createCell(remarkInfo[i], keyfont, Element.ALIGN_CENTER));
      }
      if (null != empWorkExperiences1 && empWorkExperiences1.size() > 0) {
         int size = empWorkExperiences1.size();
@@ -666,6 +703,7 @@
         }
      }
      try {
         document.add(table1);
         // 将表格添加到文档中
         document.add(basicTable);
         document.add(workheadtable);