package cc.mrbird.febs.server.hr.util; import cc.mrbird.febs.server.hr.entity.*; import cc.mrbird.febs.server.hr.po.User; import cc.mrbird.febs.server.hr.service.IEmpWorkExperienceService; import cn.hutool.core.util.StrUtil; import com.itextpdf.text.*; import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; import io.netty.util.internal.StringUtil; import org.apache.poi.hssf.usermodel.HeaderFooter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.Map; public class CreatePdf { Document document = new Document();// 建立一个Document对象 private static Font headfont;// 设置字体大小 private static Font keyfont;// 设置字体大小 private static Font textfont;// 设置字体大小 static { // 中文格式 BaseFont bfChinese; try { // 设置中文显示 bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); headfont = new Font(bfChinese, 15, Font.BOLD);// 设置字体大小 keyfont = new Font(bfChinese, 10, Font.BOLD);// 设置字体大小 textfont = new Font(bfChinese, 10, Font.NORMAL);// 设置字体大小 } catch (Exception e) { e.printStackTrace(); } } /** * 文成文件 * * @param file * 待生成的文件名 */ public CreatePdf(File file) { document.setPageSize(PageSize.A3);// 设置页面大小 try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); HeaderHandle footer=new HeaderHandle("12",Font.NORMAL,PageSize.A4); writer.setPageEvent(footer); document.open(); } catch (Exception e) { e.printStackTrace(); } } public CreatePdf() { } public void initFile(File file) { document.setPageSize(PageSize.A4);// 设置页面大小 try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); HeaderHandle footer=new HeaderHandle("12",Font.NORMAL,PageSize.A4); writer.setPageEvent(footer); document.open(); } catch (Exception e) { e.printStackTrace(); } } int maxWidth = 800; /** * 为表格添加一个内容 * * @param value * 值 * @param font * 字体 * @param align * 对齐方式 * @return 添加的文本框 */ public PdfPCell createCell(String value, Font font, int align) { PdfPCell cell = new PdfPCell(); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(align); cell.setPhrase(new Phrase(value, font)); return cell; } /** * 为表格添加一个内容 * * @param value * 值 * @param font * 字体 * @return 添加的文本框 */ public PdfPCell createCell(String value, Font font) { PdfPCell cell = new PdfPCell(); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPhrase(new Phrase(value, font)); return cell; } /** * 为表格添加一个内容 * * @param value * 值 * @param font * 字体 * @param align * 对齐方式 * @param colspan * 占多少列 * @return 添加的文本框 */ public PdfPCell createCell(String value, Font font, int align, int colspan) { PdfPCell cell = new PdfPCell(); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(align); cell.setColspan(colspan); cell.setPhrase(new Phrase(value, font)); return cell; } /** * 创建一个表格对象 * * @param colNumber * 表格的列数 * @return 生成的表格对象 */ public PdfPTable createTable(int colNumber) { PdfPTable table = new PdfPTable(colNumber); try { table.setTotalWidth(maxWidth); table.setLockedWidth(true); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBorder(1); } catch (Exception e) { e.printStackTrace(); } return table; } public PdfPTable createTable(float[] widths) { PdfPTable table = new PdfPTable(widths); try { table.setTotalWidth(maxWidth); table.setLockedWidth(true); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBorder(1); } catch (Exception e) { e.printStackTrace(); } return table; } public PdfPTable createBlankTable() { PdfPTable table = new PdfPTable(1); table.getDefaultCell().setBorder(0); table.addCell(createCell("", keyfont)); table.setSpacingAfter(20.0f); table.setSpacingBefore(20.0f); return table; } public static Font getPdfChineseFont() throws Exception { BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); 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(800); table.setHorizontalAlignment(Element.ALIGN_LEFT); // 设置单元格样式 cell.setMinimumHeight(35); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.WHITE); cell.setBorder(0); cell.setBorderWidthTop(0.1f); cell.setBorderWidthBottom(0.1f); cell.setBorderWidthLeft(0.1f); cell.setBorderWidthRight(0.1f); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(BaseColor.BLACK); cell.setBorderColorRight(BaseColor.BLACK); cell.setBorderColorTop(BaseColor.BLACK); cell.setPadding(3); } /** * @param * * @param * * @param * @param * @param baseinfo * @param empBaseInfoList * @param * @param workhead * @param empWorkExperiences1 * @param * @param empPhysicalhead * @param records * @param * @param empContractInfo * @param empContractInfos * @param * @param empJobChange * @param empJobChangeList * @param * @param leaveInfo * @param empLeaveInfos * @param * @param resign * @param empResigns * @param * @param dimissionAttend * @param dimissionAttends * @param * @param dimissionLog * @param records1 * @param * @param unemployment * @param empUnemployments * @param * @param insurance * @param empInsurances * @param * @param accidentCases * @param empAccidentCases1 * @param * @param occupational * @param empOccupationals * @param * @param laborTrouble * @param empLaborTroubles * @param * @param badRecord * @param empBadRecords * @param * @param remarkInfo * @param empRemarkInfos * @param */ public void generatePDF(String[] baseinfo, List empBaseInfoList, int baseinfolength, String[] workhead, List empWorkExperiences1, int workheadlength, String[] empPhysicalhead, List records, int empPhysicalheadlength, String[] empContractInfo, List empContractInfos, int empContractInfolength, String[] empJobChange, List> empJobChangeList, int empJobChangelength, String[] leaveInfo, List empLeaveInfos, int leaveInfolength, String[] resign, List empResigns, int resignlength, String[] dimissionAttend, List dimissionAttends, int dimissionAttendlength, String[] dimissionLog, List> records1, int dimissionLoglength, String[] unemployment, List empUnemployments, int unemploymentlength, String[] insurance, List empInsurances, int insurancelength, String[] accidentCases, List empAccidentCases1, int accidentCaseslength, String[] occupational, List empOccupationals, int occupationallength, String[] laborTrouble, List empLaborTroubles, int laborTroublelength, String[] badRecord, List empBadRecords, int badRecordlength, String[] remarkInfo, List empRemarkInfos, int remarkInfolength) { // 创建一个只有colNum列的表格 DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd"); document.addHeader("标题","标题"); EmpBaseInfo empBaseInfo = empBaseInfoList.get(0); PdfPTable workheadtable = createTable(workheadlength); PdfPTable empPhysicalheadtable = createTable(empPhysicalheadlength); PdfPTable empContractInfotable = createTable(empContractInfolength); PdfPTable empJobChangetable = createTable(empJobChangelength); PdfPTable leaveInfotable = createTable(leaveInfolength); PdfPTable resigntable = createTable(resignlength); PdfPTable dimissionAttendtable = createTable(dimissionAttendlength); PdfPTable dimissionLogtable = createTable(dimissionLoglength); PdfPTable unemploymenttable = createTable(unemploymentlength); PdfPTable insurancetable = createTable(insurancelength); PdfPTable accidentCasestable = createTable(accidentCaseslength); PdfPTable occupationaltable = createTable(occupationallength); PdfPTable laborTroubletable = createTable(laborTroublelength); PdfPTable badRecordtable = createTable(badRecordlength); PdfPTable remarkInfotable = createTable(remarkInfolength); Object[][] basicDatas = { {"编号",empBaseInfo.getEmpNumb(), "姓名",empBaseInfo.getEmpName(), "性别",empBaseInfo.getSexName()}, {"部门(护卫点)",empBaseInfo.getDeptName(), "岗位",empBaseInfo.getJobName(), "员工类别",empBaseInfo.getEmpTypeName()==null?"":empBaseInfo.getEmpTypeName()}, {"民族",empBaseInfo.getNationName()==null?"":empBaseInfo.getNationName(), "年龄",empBaseInfo.getAge()==null?"":empBaseInfo.getAge(), "婚姻状态",empBaseInfo.getMarriageName()==null?"":empBaseInfo.getMarriageName()}, {"身份证有效期",empBaseInfo.getCertificateValidity()==null?"":format1.format(empBaseInfo.getCertificateValidity()), "身高(cm)",empBaseInfo.getStature()==null?"":empBaseInfo.getStature(), "政治面貌",empBaseInfo.getPoliticsName()==null?"":empBaseInfo.getPoliticsName()}, {"出生日期",empBaseInfo.getBirthdate()==null?"":format1.format(empBaseInfo.getBirthdate()), "最高学历",empBaseInfo.getEducationName()==null?"":empBaseInfo.getEducationName(), "籍贯",empBaseInfo.getNativePlaceName()==null?"":empBaseInfo.getNativePlaceName()}, {"户籍地址",empBaseInfo.getCensusAddress()==null?"":empBaseInfo.getCensusAddress(), "现住址",empBaseInfo.getCurrentAddress()==null?"":empBaseInfo.getCurrentAddress(), "保安员回执",empBaseInfo.getReturnReceipt()==null?"":empBaseInfo.getReturnReceipt()}, {"保安员证号",empBaseInfo.getGuardNumb()==null?"":empBaseInfo.getGuardNumb(), "档案情况",empBaseInfo.getArchivesStatusName()==null?"":empBaseInfo.getArchivesStatusName(), "银行名称",empBaseInfo.getBankName()==null?"":empBaseInfo.getBankName()}, {"银行账号",empBaseInfo.getBankNumb()==null?"":empBaseInfo.getBankNumb(), "电话号码",empBaseInfo.getTelePhone()==null?"":empBaseInfo.getTelePhone(), "入职日期",empBaseInfo.getEntryDate()==null?"":format1.format(empBaseInfo.getEntryDate())}, {"保险类型",empBaseInfo.getInsuranceType()==null?"":empBaseInfo.getInsuranceType(), "社保电脑号",empBaseInfo.getSocialNumb()==null?"":empBaseInfo.getSocialNumb(), "招聘介绍人",empBaseInfo.getIntroducer()==null?"":empBaseInfo.getIntroducer()}, {"入司工龄",empBaseInfo.getSeniority()==null?"":empBaseInfo.getSeniority(), "工作证",empBaseInfo.getEmpCardStatusName()==null?"":empBaseInfo.getEmpCardStatusName(), "家庭成员及关系",empBaseInfo.getFamily()==null?"":empBaseInfo.getFamily()}, {"紧急联系电话",empBaseInfo.getUrgencyPhone()==null?"":empBaseInfo.getUrgencyPhone(), "员工手册",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 PdfPTable basicTable = new PdfPTable(widthss); basicTable.addCell(createCell("基本信息:", keyfont, Element.ALIGN_LEFT,basicDatas.length, false)); // 添加备注,靠左,不显示边框 // 外层循环表格的行 for (int i = 0; i < basicDatas.length; i++) { // 内层循环每一行具体数据 for (int j = 0; j < basicDatas[i].length; j++) { // 新建一个cell PdfPCell cell = new PdfPCell(); // 这个方法是统一设置表格和cell的样式,下面会写 setTableStyle(basicTable, cell); // cell中需要填充数据的格式 Paragraph paragraph = null; try { paragraph = new Paragraph(StrUtil.toString(basicDatas[i][j]), getPdfChineseFont()); } catch (Exception e) { e.printStackTrace(); } // 设置cell的值 cell.setPhrase(paragraph); // 将cell添加到表格中 basicTable.addCell(cell); } } // 添加备注,靠左,不显示边框 workheadtable.addCell(createCell("工作经历:", keyfont, Element.ALIGN_LEFT, workheadlength, false)); // 添加备注,靠左,不显示边框 empPhysicalheadtable.addCell(createCell("体检信息:", keyfont, Element.ALIGN_LEFT, empPhysicalheadlength, false)); // 添加备注,靠左,不显示边框 empContractInfotable.addCell(createCell("合同信息:", keyfont, Element.ALIGN_LEFT, empContractInfolength, false)); // 添加备注,靠左,不显示边框 empJobChangetable.addCell(createCell("调岗记录:", keyfont, Element.ALIGN_LEFT, empJobChangelength, false)); // 添加备注,靠左,不显示边框 leaveInfotable.addCell(createCell("请假记录:", keyfont, Element.ALIGN_LEFT, leaveInfolength, false)); // 添加备注,靠左,不显示边框 resigntable.addCell(createCell("辞职申请:", keyfont, Element.ALIGN_LEFT, resignlength, false)); // 添加备注,靠左,不显示边框 dimissionAttendtable.addCell(createCell("离职当月考勤:", keyfont, Element.ALIGN_LEFT, dimissionAttendlength, false)); // 添加备注,靠左,不显示边框 dimissionLogtable.addCell(createCell("入离职记录:", keyfont, Element.ALIGN_LEFT, dimissionLoglength, false)); // 添加备注,靠左,不显示边框 unemploymenttable.addCell(createCell("失业金领取:", keyfont, Element.ALIGN_LEFT, unemploymentlength, false)); // 添加备注,靠左,不显示边框 insurancetable.addCell(createCell("社保申请:", keyfont, Element.ALIGN_LEFT, insurancelength, false)); // 添加备注,靠左,不显示边框 accidentCasestable.addCell(createCell("意外险案件:", keyfont, Element.ALIGN_LEFT, accidentCaseslength, false)); // 添加备注,靠左,不显示边框 occupationaltable.addCell(createCell("工伤案件:", keyfont, Element.ALIGN_LEFT, occupationallength, false)); // 添加备注,靠左,不显示边框 laborTroubletable.addCell(createCell("劳资案件:", keyfont, Element.ALIGN_LEFT, laborTroublelength, false));// 添加备注,靠左,不显示边框 badRecordtable.addCell(createCell("不良记录:", keyfont, Element.ALIGN_LEFT, badRecordlength, false)); // 添加备注,靠左,不显示边框 remarkInfotable.addCell(createCell("备注:", keyfont, Element.ALIGN_LEFT, remarkInfolength, false)); // 添加备注,靠左,不显示边框 // 设置表头 for (int i = 0; i < workheadlength; i++) { workheadtable.addCell(createCell(workhead[i], keyfont, Element.ALIGN_CENTER)); } for (int i = 0; i < empPhysicalheadlength; i++) { empPhysicalheadtable.addCell(createCell(empPhysicalhead[i], keyfont, Element.ALIGN_CENTER)); } for (int i = 0; i < empContractInfolength; i++) { empContractInfotable.addCell(createCell(empContractInfo[i], keyfont, Element.ALIGN_CENTER)); } for (int i = 0; i < empJobChangelength; i++) { empJobChangetable.addCell(createCell(empJobChange[i], keyfont, Element.ALIGN_CENTER)); } for (int i = 0; i < leaveInfolength; i++) { leaveInfotable.addCell(createCell(leaveInfo[i], keyfont, Element.ALIGN_CENTER)); } for (int i = 0; i < resignlength; i++) { resigntable.addCell(createCell(resign[i], keyfont, Element.ALIGN_CENTER)); } for (int i = 0; i < dimissionAttendlength; i++) { dimissionAttendtable.addCell(createCell(dimissionAttend[i], keyfont, Element.ALIGN_CENTER)); } for (int i = 0; i < dimissionLoglength; i++) { dimissionLogtable.addCell(createCell(dimissionLog[i], keyfont, Element.ALIGN_CENTER)); } for (int i = 0; i < unemploymentlength; i++) { unemploymenttable.addCell(createCell(unemployment[i], keyfont, Element.ALIGN_CENTER)); } for (int i = 0; i < insurancelength; i++) { insurancetable.addCell(createCell(insurance[i], keyfont, Element.ALIGN_CENTER)); } for (int i = 0; i < accidentCaseslength; i++) { accidentCasestable.addCell(createCell(accidentCases[i], keyfont, Element.ALIGN_CENTER)); } for (int i = 0; i < occupationallength; i++) { occupationaltable.addCell(createCell(occupational[i], keyfont, Element.ALIGN_CENTER)); } for (int i = 0; i < laborTroublelength; i++) { laborTroubletable.addCell(createCell(laborTrouble[i], keyfont, Element.ALIGN_CENTER)); } for (int i = 0; i < badRecordlength; i++) { badRecordtable.addCell(createCell(badRecord[i], keyfont, Element.ALIGN_CENTER)); } 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(); for (int i = 0; i < size; i++) { EmpWorkExperience user = empWorkExperiences1.get(i); workheadtable.addCell(createCell(user.getBeginDate()==null?"":format1.format(user.getBeginDate()), textfont)); workheadtable.addCell(createCell(user.getEndDate()==null?"":format1.format(user.getEndDate()), textfont)); workheadtable.addCell(createCell(user.getWorkUnit()==null?"":user.getWorkUnit(), textfont)); workheadtable.addCell(createCell(user.getJobContent()==null?"":user.getJobContent() , textfont)); } } if (null != records && records.size() > 0) { int size = records.size(); for (int i = 0; i < size; i++) { EmpPhysicalExam user = records.get(i); empPhysicalheadtable.addCell(createCell(user.getHospital()==null?"":user.getHospital(), textfont)); empPhysicalheadtable.addCell(createCell(user.getPhysicalExamDate()==null?"":format1.format(user.getPhysicalExamDate()), textfont)); empPhysicalheadtable.addCell(createCell(user.getPhysicalExamTypeName()==null?"":user.getPhysicalExamTypeName(), textfont)); empPhysicalheadtable.addCell(createCell(user.getBloodPressure()==null?"":user.getBloodPressure(), textfont)); empPhysicalheadtable.addCell(createCell(user.getTransaminase()==null?"":user.getTransaminase(), textfont)); empPhysicalheadtable.addCell(createCell(user.getEcgName()==null?"":user.getEcgName(), textfont)); empPhysicalheadtable.addCell(createCell(user.getConclusion()==null?"":user.getConclusion(), textfont)); empPhysicalheadtable.addCell(createCell(user.getReviewRecord()==null?"":user.getReviewRecord(), textfont)); empPhysicalheadtable.addCell(createCell(user.getRemark()==null?"":user.getRemark(), textfont)); } } if (null != empContractInfos && empContractInfos.size() > 0) { int size = empContractInfos.size(); for (int i = 0; i < size; i++) { EmpContractInfo user = empContractInfos.get(i); empContractInfotable.addCell(createCell(user.getSigningDate()==null?"":format1.format(user.getSigningDate()), textfont)); empContractInfotable.addCell(createCell(user.getEndDate()==null?"":format1.format(user.getEndDate()), textfont)); empContractInfotable.addCell(createCell(user.getContractPeriod()==null?"":String.valueOf(user.getContractPeriod()), textfont)); empContractInfotable.addCell(createCell(user.getContractStatusName()==null?"":user.getContractStatusName(), textfont)); empContractInfotable.addCell(createCell(user.getTransactor()==null?"":user.getTransactor() , textfont)); } } if (null != empJobChangeList && empJobChangeList.size() > 0) { int size = empJobChangeList.size(); for (int i = 0; i < size; i++) { Map user = empJobChangeList.get(i); empJobChangetable.addCell(createCell(user.get("newDeptName")==null?"":user.get("newDeptName").toString(), textfont)); empJobChangetable.addCell(createCell(user.get("newJobName")==null?"":user.get("newJobName").toString(), textfont)); empJobChangetable.addCell(createCell(user.get("empName")==null?"":user.get("empName").toString(), textfont)); empJobChangetable.addCell(createCell(user.get("oldDeptName")==null?"":user.get("oldDeptName").toString(), textfont)); empJobChangetable.addCell(createCell(user.get("oldJobName")==null?"":user.get("oldJobName").toString(), textfont)); empJobChangetable.addCell(createCell(user.get("changeDate")==null?"":user.get("changeDate").toString(), textfont)); empJobChangetable.addCell(createCell(user.get("changeType")==null?"":user.get("changeType").toString(), textfont)); } } if (null != records1 && records1.size() > 0) { int size = records1.size(); for (int i = 0; i < size; i++) { Map user = records1.get(i); dimissionLogtable.addCell(createCell(user.get("entryDate")==null?"":user.get("entryDate").toString(), textfont)); dimissionLogtable.addCell(createCell(user.get("dimissionDate")==null?"":user.get("dimissionDate").toString(), textfont)); dimissionLogtable.addCell(createCell(user.get("dimissionType")==null?"":user.get("dimissionType").toString(), textfont)); dimissionLogtable.addCell(createCell(user.get("selfLeaveDay")==null?"":user.get("selfLeaveDay").toString(), textfont)); dimissionLogtable.addCell(createCell(user.get("reporter")==null?"":user.get("reporter").toString(), textfont)); dimissionLogtable.addCell(createCell(user.get("remark")==null?"":user.get("remark").toString(), textfont)); } } if (null != empLeaveInfos && empLeaveInfos.size() > 0) { int size = empLeaveInfos.size(); for (int i = 0; i < size; i++) { EmpLeaveInfo user = empLeaveInfos.get(i); leaveInfotable.addCell(createCell(user.getBeginTime()==null?"":format1.format(user.getBeginTime()), textfont)); leaveInfotable.addCell(createCell(user.getEndTime()==null?"":format1.format(user.getEndTime()), textfont)); leaveInfotable.addCell(createCell(user.getLeaveDay()==null?"":String.valueOf(user.getLeaveDay()), textfont)); leaveInfotable.addCell(createCell(user.getLeaveTypeName()==null?"":user.getLeaveTypeName(), textfont)); leaveInfotable.addCell(createCell(user.getReturnDate()==null?"":format1.format(user.getReturnDate()), textfont)); leaveInfotable.addCell(createCell(user.getReporter()==null?"":user.getReporter() , textfont)); leaveInfotable.addCell(createCell(user.getRemark()==null?"":user.getRemark() , textfont)); } } if (null != empResigns && empResigns.size() > 0) { int size = empResigns.size(); for (int i = 0; i < size; i++) { EmpResign user = empResigns.get(i); resigntable.addCell(createCell(user.getApplayDate()==null?"":format1.format(user.getApplayDate()), textfont)); resigntable.addCell(createCell(user.getReason()==null?"":user.getReason(), textfont)); resigntable.addCell(createCell(user.getReporter()==null?"":user.getReporter() , textfont)); resigntable.addCell(createCell(user.getRemark()==null?"":user.getRemark() , textfont)); } } if (null != dimissionAttends && dimissionAttends.size() > 0) { int size = dimissionAttends.size(); for (int i = 0; i < size; i++) { EmpDimissionAttend user = dimissionAttends.get(i); dimissionAttendtable.addCell(createCell(user.getAttendMonth()==null?"":user.getAttendMonth(), textfont)); dimissionAttendtable.addCell(createCell(user.getAttendDays()==null?"":user.getAttendDays().toString() , textfont)); dimissionAttendtable.addCell(createCell(user.getOvertimeDay()==null?"":user.getOvertimeDay().toString(), textfont)); dimissionAttendtable.addCell(createCell(user.getOvertimeHour()==null?"":user.getOvertimeHour().toString(), textfont)); dimissionAttendtable.addCell(createCell(user.getDeduct()==null?"":user.getDeduct(), textfont)); dimissionAttendtable.addCell(createCell(user.getLeaveDay()==null?"":user.getLeaveDay().toString(), textfont)); dimissionAttendtable.addCell(createCell(user.getAbsenteeism()==null?"":user.getAbsenteeism().toString(), textfont)); dimissionAttendtable.addCell(createCell(user.getRemark()==null?"":user.getRemark() , textfont)); } } if (null != empUnemployments && empUnemployments.size() > 0) { int size = empUnemployments.size(); for (int i = 0; i < size; i++) { EmpUnemployment user = empUnemployments.get(i); unemploymenttable.addCell(createCell(user.getApplayDate()==null?"":format1.format(user.getApplayDate()), textfont)); unemploymenttable.addCell(createCell(user.getApplayReason()==null?"":user.getApplayReason().toString() , textfont)); unemploymenttable.addCell(createCell(user.getReporter()==null?"":user.getReporter().toString(), textfont)); unemploymenttable.addCell(createCell(user.getAuditor()==null?"":user.getAuditor().toString(), textfont)); unemploymenttable.addCell(createCell(user.getRemark()==null?"":user.getRemark() , textfont)); } } if (null != empInsurances && empInsurances.size() > 0) { int size = empInsurances.size(); for (int i = 0; i < size; i++) { EmpInsurance user = empInsurances.get(i); insurancetable.addCell(createCell(user.getApplayDate()==null?"":format1.format(user.getApplayDate()), textfont)); insurancetable.addCell(createCell(user.getProposer()==null?"":user.getProposer().toString() , textfont)); insurancetable.addCell(createCell(user.getInsuranceGaers()==null?"":user.getInsuranceGaers().toString(), textfont)); insurancetable.addCell(createCell(user.getReportStatusName()==null?"":user.getReportStatusName().toString(), textfont)); insurancetable.addCell(createCell(user.getApplayStatusName()==null?"":user.getApplayStatusName().toString(), textfont)); insurancetable.addCell(createCell(user.getAuditor()==null?"":user.getAuditor().toString(), textfont)); insurancetable.addCell(createCell(user.getRemark()==null?"":user.getRemark() , textfont)); } } if (null != empAccidentCases1 && empAccidentCases1.size() > 0) { int size = empAccidentCases1.size(); for (int i = 0; i < size; i++) { EmpAccidentCases user = empAccidentCases1.get(i); accidentCasestable.addCell(createCell(user.getInjuredTime()==null?"":format1.format(user.getInjuredTime()), textfont)); accidentCasestable.addCell(createCell(user.getInjuredAddress()==null?"":user.getInjuredAddress().toString() , textfont)); accidentCasestable.addCell(createCell(user.getInjuredPart()==null?"":user.getInjuredPart().toString(), textfont)); accidentCasestable.addCell(createCell(user.getInjuredDescribe()==null?"":user.getInjuredDescribe().toString(), textfont)); accidentCasestable.addCell(createCell(user.getInjuredDiacrisis()==null?"":user.getInjuredDiacrisis().toString(), textfont)); accidentCasestable.addCell(createCell(user.getHospitalName()==null?"":user.getHospitalName().toString(), textfont)); accidentCasestable.addCell(createCell(user.getHospitalizatioFlagName()==null?"":user.getHospitalizatioFlagName().toString(), textfont)); accidentCasestable.addCell(createCell(user.getBedNumb()==null?"":user.getBedNumb().toString(), textfont)); accidentCasestable.addCell(createCell(user.getReprotTime()==null?"":format1.format(user.getReprotTime()), textfont)); accidentCasestable.addCell(createCell(user.getSubmitTime()==null?"":format1.format(user.getSubmitTime()), textfont)); accidentCasestable.addCell(createCell(user.getSbumitBy()==null?"":user.getSbumitBy().toString(), textfont)); accidentCasestable.addCell(createCell(user.getExpensesFee()==null?"":user.getExpensesFee().toString(), textfont)); accidentCasestable.addCell(createCell(user.getInnsureFee()==null?"":user.getInnsureFee().toString() , textfont)); } } if (null != empOccupationals && empOccupationals.size() > 0) { int size = empOccupationals.size(); for (int i = 0; i < size; i++) { EmpOccupational user = empOccupationals.get(i); occupationaltable.addCell(createCell(user.getInjuredTime()==null?"":format1.format(user.getInjuredTime()), textfont)); occupationaltable.addCell(createCell(user.getInjuredAddress()==null?"":user.getInjuredAddress().toString() , textfont)); occupationaltable.addCell(createCell(user.getInjuredPart()==null?"":user.getInjuredPart().toString(), textfont)); occupationaltable.addCell(createCell(user.getInjuredDescribe()==null?"":user.getInjuredDescribe().toString(), textfont)); occupationaltable.addCell(createCell(user.getInjuredDiacrisis()==null?"":user.getInjuredDiacrisis().toString(), textfont)); occupationaltable.addCell(createCell(user.getHospitalName()==null?"":user.getHospitalName().toString(), textfont)); occupationaltable.addCell(createCell(user.getHospitalizatioFlagName()==null?"":user.getHospitalizatioFlagName().toString(), textfont)); occupationaltable.addCell(createCell(user.getBedNumb()==null?"":user.getBedNumb().toString(), textfont)); occupationaltable.addCell(createCell(user.getReportTime()==null?"":format1.format(user.getReportTime()), textfont)); occupationaltable.addCell(createCell(user.getSubmitTime()==null?"":format1.format(user.getSubmitTime()), textfont)); occupationaltable.addCell(createCell(user.getSbumitBy()==null?"":user.getSbumitBy().toString(), textfont)); occupationaltable.addCell(createCell(user.getExpensesFee()==null?"":user.getExpensesFee().toString(), textfont)); occupationaltable.addCell(createCell(user.getCompensated()==null?"":user.getCompensated().toString() , textfont)); } } if (null != empLaborTroubles && empLaborTroubles.size() > 0) { int size = empLaborTroubles.size(); for (int i = 0; i < size; i++) { EmpLaborTrouble user = empLaborTroubles.get(i); laborTroubletable.addCell(createCell(user.getArbitrationDate()==null?"":format1.format(user.getArbitrationDate()), textfont)); laborTroubletable.addCell(createCell(user.getArbitrationTypeName()==null?"":user.getArbitrationTypeName().toString() , textfont)); laborTroubletable.addCell(createCell(user.getArbitrationReason()==null?"":user.getArbitrationReason().toString(), textfont)); laborTroubletable.addCell(createCell(user.getReporter()==null?"":user.getReporter().toString(), textfont)); laborTroubletable.addCell(createCell(user.getRemark()==null?"":user.getRemark().toString(), textfont)); laborTroubletable.addCell(createCell(user.getArbitrationPay()==null?"":user.getArbitrationPay().toString(), textfont)); laborTroubletable.addCell(createCell(user.getArbitrationStatusName()==null?"":user.getArbitrationStatusName().toString(), textfont)); laborTroubletable.addCell(createCell(user.getSettleDate()==null?"":format1.format(user.getSettleDate()), textfont)); } } if (null != empBadRecords && empBadRecords.size() > 0) { int size = empBadRecords.size(); for (int i = 0; i < size; i++) { EmpBadRecord user = empBadRecords.get(i); badRecordtable.addCell(createCell(user.getBadDate()==null?"":format1.format(user.getBadDate()), textfont)); badRecordtable.addCell(createCell(user.getBadContent()==null?"":user.getBadContent().toString() , textfont)); badRecordtable.addCell(createCell(user.getReporter()==null?"":user.getReporter().toString(), textfont)); badRecordtable.addCell(createCell(user.getRemark()==null?"":user.getRemark().toString(), textfont)); } } if (null != empRemarkInfos && empRemarkInfos.size() > 0) { int size = empRemarkInfos.size(); for (int i = 0; i < size; i++) { EmpRemarkInfo user = empRemarkInfos.get(i); remarkInfotable.addCell(createCell(user.getRemarkDate()==null?"":format1.format(user.getRemarkDate()), textfont)); remarkInfotable.addCell(createCell(user.getRemarkContent()==null?"":user.getRemarkContent().toString() , textfont)); } } try { document.add(table1); // 将表格添加到文档中 document.add(basicTable); document.add(workheadtable); document.add(empPhysicalheadtable); document.add(empContractInfotable); document.add(empJobChangetable); document.add(leaveInfotable); document.add(resigntable); document.add(dimissionAttendtable); document.add(dimissionLogtable); document.add(unemploymenttable); document.add(insurancetable); document.add(accidentCasestable); document.add(occupationaltable); document.add(laborTroubletable); document.add(badRecordtable); document.add(remarkInfotable); } catch (DocumentException e) { e.printStackTrace(); } // 关闭流 document.close(); } /** * 提供外界调用的接口,生成以head为表头,list为数据的pdf * * @param * //数据表头 * @param * //数据 * @param * @param baseinfo * @param empBaseInfoList * @param workhead * @param empWorkExperiences1 * @param empPhysicalhead * @param records * @param empContractInfo * @param empContractInfos * @param empJobChange * @param empJobChangeList * @param leaveInfo * @param empLeaveInfos * @param resign * @param empResigns * @param dimissionAttend * @param dimissionAttends * @param dimissionLog * @param records1 * @param unemployment * @param empUnemployments * @param insurance * @param empInsurances * @param accidentCases * @param empAccidentCases1 * @param occupational * @param empOccupationals * @param laborTrouble * @param empLaborTroubles * @param badRecord * @param empBadRecords * @param remarkInfo * @param empRemarkInfos * @param response * @return //excel所在的路径 */ public String generatePDFs(String[] baseinfo, List empBaseInfoList, String[] workhead, List empWorkExperiences1, String[] empPhysicalhead, List records, String[] empContractInfo, List empContractInfos, String[] empJobChange, List> empJobChangeList, String[] leaveInfo, List empLeaveInfos, String[] resign, List empResigns, String[] dimissionAttend, List dimissionAttends, String[] dimissionLog, List> records1, String[] unemployment, List empUnemployments, String[] insurance, List empInsurances, String[] accidentCases, List empAccidentCases1, String[] occupational, List empOccupationals, String[] laborTrouble, List empLaborTroubles, String[] badRecord, List empBadRecords, String[] remarkInfo, List empRemarkInfos, HttpServletResponse response) { final String FilePath = "pdfPath"; String saveFilePathAndName = ""; // 获得存储的根目录 String savePath = new GetFilePlace().getFileDirFromProperties(FilePath); // 获得当天存储的路径,不存在则生成当天的文件夹 String realSavePath = new GenerateFold().getFold(savePath); saveFilePathAndName = new GenerateFileName().generateFileName(realSavePath, "pdf",empBaseInfoList.get(0).getEmpName()); File file = new File(saveFilePathAndName); try { file.createNewFile(); } catch (IOException e1) { e1.printStackTrace(); } initFile(file); try { file.createNewFile(); // 生成一个pdf文件 } catch (IOException e) { e.printStackTrace(); } new CreatePdf(file).generatePDF(baseinfo,empBaseInfoList,baseinfo.length, workhead, empWorkExperiences1,workhead.length, empPhysicalhead,records,empPhysicalhead.length, empContractInfo,empContractInfos,empContractInfo.length, empJobChange,empJobChangeList,empJobChange.length, leaveInfo,empLeaveInfos,leaveInfo.length, resign,empResigns,resign.length, dimissionAttend,dimissionAttends,dimissionAttend.length, dimissionLog,records1,dimissionLog.length, unemployment,empUnemployments,unemployment.length, insurance,empInsurances,insurance.length, accidentCases,empAccidentCases1,accidentCases.length, occupational,empOccupationals,occupational.length, laborTrouble,empLaborTroubles,laborTrouble.length, badRecord,empBadRecords,badRecord.length, remarkInfo,empRemarkInfos,remarkInfo.length); return saveFilePathAndName; } }