package com.zhgd.xmgl.pdf;

import com.google.gson.JsonObject;
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.draw.DottedLineSeparator;
import com.itextpdf.text.pdf.draw.LineSeparator;
import com.zhgd.jeecg.common.mybatis.EntityMap;
import org.apache.commons.collections.MapUtils;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @program: wisdomSite
 * @description:
 * @author: Mr.Peng
 * @create: 2022-06-01 11:28
 **/

public class PdfUtils {
    // 定义全局的字体静态变量
    private static Font titlefont;
    private static Font headfont;
    private static Font keyfont;
    private static Font textfont;
    // 静态代码块
    static {
        try {
            // 不同字体（这里定义为同一种字体：包含不同字号、不同style）
            BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            titlefont = new Font(bfChinese, 16, Font.BOLD);
            headfont = new Font(bfChinese, 14, Font.BOLD);
            keyfont = new Font(bfChinese, 10, Font.BOLD);
            textfont = new Font(bfChinese, 10, Font.NORMAL);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    // 生成PDF文件
    public static void generatePDF1(Document document, List<EntityMap> list, String monthTitle,String projectName) throws Exception {
        // 优化打印后的签名宽高
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        textfont = new Font(bfChinese, 13, Font.NORMAL);
        // 优化打印
        //textfont = new Font(bfChinese, 15, Font.NORMAL);
        // 段落
        Paragraph paragraph = new Paragraph("工人考勤表", titlefont);
        paragraph.setAlignment(1); // 设置文字居中 0靠左 1，居中 2，靠右
        paragraph.setIndentationLeft(12); // 设置左缩进
        paragraph.setIndentationRight(12); // 设置右缩进
        paragraph.setFirstLineIndent(24); // 设置首行缩进
        paragraph.setLeading(20f); // 行间距
        paragraph.setSpacingBefore(5f); // 设置段落上空白
        paragraph.setSpacingAfter(10f); // 设置段落下空白
        // 直线
        Paragraph p1 = new Paragraph();
        p1.add(new Chunk(new LineSeparator()));
        // 点线
        Paragraph p2 = new Paragraph();
        p2.add(new Chunk(new DottedLineSeparator()));
        // 超链接
        // Anchor anchor = new Anchor("日期");
        //// anchor.setReference("2020");
        // // 定位
        // Anchor gotoP = new Anchor("项目名称");
        // gotoP.setReference("#top");
        // 添加图片
        // Image image =
        // Image.getInstance("https://img-blog.csdn.net/20180801174617455?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zNzg0ODcxMA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70");
        // image.setAlignment(Image.ALIGN_CENTER);
        // image.scalePercent(40); //依照比例缩放
        // 表格
        // PdfPTable table = createTable(new float[] { 40, 120, 120, 120, 80, 80
        // });
        PdfPTable table = createTable2(38);
        table.setWidthPercentage(100); // 宽度100%填充
//		float[] columnWidths = { 0.8f, 1.8f, 2.5f, 2.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f,
//				0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f,
//				0.5f, 0.5f, 0.5f, 0.5f, 1.2f, 1.5f, 2.5f };
        // 优化打印后的签名宽高
        float[] columnWidths = { 0.8f, 1.8f, 2.5f, 2.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f,
                0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f,
                0.5f, 0.5f, 0.5f, 0.5f, 1.2f, 3.0f, 2.5f };
        table.setWidths(columnWidths);

        table.addCell(createCell("时间: " + monthTitle, headfont, Element.ALIGN_LEFT, 38, false));
        table.addCell(createCell("项目名称： " + projectName, headfont, Element.ALIGN_LEFT, 38, false));
        table.addCell(createCell("序号", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("姓名", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("部门/班组", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("人员类型", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("1", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("2", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("3", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("4", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("5", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("6", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("7", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("8", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("9", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("10", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("11", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("12", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("13", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("14", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("15", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("16", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("17", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("18", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("19", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("20", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("21", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("22", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("23", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("24", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("25", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("26", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("27", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("28", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("29", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("30", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("31", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("出勤天数合计", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("本人签名确认", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("备注", keyfont, Element.ALIGN_CENTER));
        int index=0;
        for (EntityMap data:list) {
            table.addCell(myCreateCell(String.valueOf(index + 1), textfont));
            index++;
            // 出勤合计
            int cqMaxx = 0;
            table.addCell(myCreateCell(MapUtils.getString(data,"workerName"), textfont));
            table.addCell(myCreateCell(MapUtils.getString(data,"departmentTeamName"), textfont));
            table.addCell(myCreateCell(MapUtils.getString(data,"personTypeName"), textfont));
            String cq1 = "";
            if (!"0".equals(MapUtils.getString(data,"day1"))) {
                cq1 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq1 = " ";
            }
            table.addCell(myCreateCell(cq1, textfont));
            String cq2 = "";
            if (!"0".equals(MapUtils.getString(data,"day2"))) {
                cq2 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq2 = " ";
            }
            table.addCell(myCreateCell(cq2, textfont));
            String cq3 = "";
            if (!"0".equals(MapUtils.getString(data,"day3"))) {
                cq3 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq3 = " ";
            }
            table.addCell(myCreateCell(cq3, textfont));
            String cq4 = "";
            if (!"0".equals(MapUtils.getString(data,"day4"))) {
                cq4 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq4 = " ";
            }
            table.addCell(myCreateCell(cq4, textfont));
            String cq5 = "";
            if (!"0".equals(MapUtils.getString(data,"day5"))) {
                cq5 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq5 = " ";
            }
            table.addCell(myCreateCell(cq5, textfont));
            String cq6 = "";
            if (!"0".equals(MapUtils.getString(data,"day6"))) {
                cq6 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq6 = " ";
            }
            table.addCell(myCreateCell(cq6, textfont));
            String cq7 = "";
            if (!"0".equals(MapUtils.getString(data,"day7"))) {
                cq7 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq7 = " ";
            }
            table.addCell(myCreateCell(cq7, textfont));
            String cq8 = "";
            if (!"0".equals(MapUtils.getString(data,"day8"))) {
                cq8 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq8 = " ";
            }
            table.addCell(myCreateCell(cq8, textfont));
            String cq9 = "";
            if (!"0".equals(MapUtils.getString(data,"day9"))) {
                cq9 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq9 = " ";
            }
            table.addCell(myCreateCell(cq9, textfont));
            String cq10 = "";
            if (!"0".equals(MapUtils.getString(data,"day10"))) {
                cq10 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq10 = " ";
            }
            table.addCell(myCreateCell(cq10, textfont));
            String cq11 = "";
            if (!"0".equals(MapUtils.getString(data,"day11"))) {
                cq11 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq11 = " ";
            }
            table.addCell(myCreateCell(cq11, textfont));
            String cq12 = "";
            if (!"0".equals(MapUtils.getString(data,"day12"))) {
                cq12 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq12 = " ";
            }
            table.addCell(myCreateCell(cq12, textfont));
            String cq13 = "";
            if (!"0".equals(MapUtils.getString(data,"day13"))) {
                cq13 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq13 = " ";
            }
            table.addCell(myCreateCell(cq13, textfont));
            String cq14 = "";
            if (!"0".equals(MapUtils.getString(data,"day14"))) {
                cq14 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq14 = " ";
            }
            table.addCell(myCreateCell(cq14, textfont));
            String cq15 = "";
            if (!"0".equals(MapUtils.getString(data,"day15"))) {
                cq15 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq15 = " ";
            }
            table.addCell(myCreateCell(cq15, textfont));
            String cq16 = "";
            if (!"0".equals(MapUtils.getString(data,"day16"))) {
                cq16 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq16 = " ";
            }
            table.addCell(myCreateCell(cq16, textfont));
            String cq17 = "";
            if (!"0".equals(MapUtils.getString(data,"day17"))) {
                cq17 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq17 = " ";
            }
            table.addCell(myCreateCell(cq17, textfont));
            String cq18 = "";
            if (!"0".equals(MapUtils.getString(data,"day18"))) {
                cq18 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq18 = " ";
            }
            table.addCell(myCreateCell(cq18, textfont));
            String cq19 = "";
            if (!"0".equals(MapUtils.getString(data,"day19"))) {
                cq19 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq19 = " ";
            }
            table.addCell(myCreateCell(cq19, textfont));
            String cq20 = "";
            if (!"0".equals(MapUtils.getString(data,"day20"))) {
                cq20 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq20 = " ";
            }
            table.addCell(myCreateCell(cq20, textfont));
            String cq21 = "";
            if (!"0".equals(MapUtils.getString(data,"day21"))) {
                cq21 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq21 = " ";
            }
            table.addCell(myCreateCell(cq21, textfont));
            String cq22 = "";
            if (!"0".equals(MapUtils.getString(data,"day22"))) {
                cq22 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq22 = " ";
            }
            table.addCell(myCreateCell(cq22, textfont));
            String cq23 = "";
            if (!"0".equals(MapUtils.getString(data,"day23"))) {
                cq23 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq23 = " ";
            }
            table.addCell(myCreateCell(cq23, textfont));
            String cq24 = "";
            if (!"0".equals(MapUtils.getString(data,"day24"))) {
                cq24 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq24 = " ";
            }
            table.addCell(myCreateCell(cq24, textfont));
            String cq25 = "";
            if (!"0".equals(MapUtils.getString(data,"day25"))) {
                cq25 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq25 = " ";
            }
            table.addCell(myCreateCell(cq25, textfont));
            String cq26 = "";
            if (!"0".equals(MapUtils.getString(data,"day26"))) {
                cq26 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq26 = " ";
            }
            table.addCell(myCreateCell(cq26, textfont));
            String cq27 = "";
            if (!"0".equals(MapUtils.getString(data,"day27"))) {
                cq27 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq27 = " ";
            }
            table.addCell(myCreateCell(cq27, textfont));
            String cq28 = "";
            if (!"0".equals(MapUtils.getString(data,"day28"))) {
                cq28 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq28 = " ";
            }
            table.addCell(myCreateCell(cq28, textfont));
            String cq29 = "";
            if (!"0".equals(MapUtils.getString(data,"day29"))) {
                cq29 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq29 = " ";
            }
            table.addCell(myCreateCell(cq29, textfont));
            String cq30 = "";
            if (!"0".equals(MapUtils.getString(data,"day30"))) {
                cq30 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq30 = " ";
            }
            table.addCell(myCreateCell(cq30, textfont));
            String cq31 = "";
            if (!"0".equals(MapUtils.getString(data,"day31"))) {
                cq31 = "√";
                cqMaxx = cqMaxx + 1;
            } else {
                cq31 = " ";
            }
            table.addCell(myCreateCell(cq31, textfont));
            table.addCell(myCreateCell(String.valueOf(cqMaxx), textfont));
            table.addCell(myCreateCell("        ", textfont));
            table.addCell(myCreateCell("      ", textfont));
        }
        document.add(paragraph);
        // document.add(anchor);
        document.add(p2);
        // document.add(gotoP);
        document.add(p1);
        document.add(table);
        // document.add(image);
    }



    // 生成PDF文件
    public static void generatePDF2(Document document, java.util.List<EntityMap> list, String projectName, String monthTitle)
            throws Exception {
        double payNetmaYf = 0.0;
        double payNetmaSf = 0.0;
        if (list.size() > 0) {
            for(EntityMap data:list){
                payNetmaSf = payNetmaSf + MapUtils.getDouble(data,"payNet",0d);
                payNetmaYf = payNetmaYf + MapUtils.getDouble(data,"payGross",0d);
            }
        }
        //换算
        DecimalFormat df = new DecimalFormat("0.00");
        String str = df.format(payNetmaYf);
        BigDecimal bigDecimalk = new BigDecimal(str);
        String strssk = bigDecimalk.toPlainString();
        //log.info("2:" + strssk);

        DecimalFormat df2 = new DecimalFormat("0.00");
        String str2 = df2.format(payNetmaSf);
        BigDecimal bigDecimalk2 = new BigDecimal(str2);
        String strssk2 = bigDecimalk2.toPlainString();
        //log.info("2:" + strssk2);
        // 段落
        Paragraph paragraph = new Paragraph(projectName + "工资表" + monthTitle, titlefont);
        paragraph.setAlignment(1); // 设置文字居中 0靠左 1，居中 2，靠右
        paragraph.setIndentationLeft(12); // 设置左缩进
        paragraph.setIndentationRight(12); // 设置右缩进
        paragraph.setFirstLineIndent(24); // 设置首行缩进
        paragraph.setLeading(20f); // 行间距
        paragraph.setSpacingBefore(5f); // 设置段落上空白
        paragraph.setSpacingAfter(10f); // 设置段落下空白
        Paragraph paragraph2 = new Paragraph("施工单位：(盖章)", textfont);
        paragraph2.setAlignment(0); // 设置文字居中 0靠左 1，居中 2，靠右
        paragraph2.setIndentationLeft(12); // 设置左缩进
        paragraph2.setIndentationRight(12); // 设置右缩进
        paragraph2.setFirstLineIndent(24); // 设置首行缩进
        paragraph2.setLeading(0); // 行间距
        paragraph2.setSpacingBefore(45f); // 设置段落上空白
        paragraph2.setSpacingAfter(0); // 设置段落下空白
        Paragraph paragraph3 = new Paragraph("应发工资总金额：￥" + strssk, textfont);
        paragraph3.setAlignment(2); // 设置文字居中 0靠左 1，居中 2，靠右
        paragraph3.setIndentationLeft(12); // 设置左缩进
        paragraph3.setIndentationRight(12); // 设置右缩进
        paragraph3.setFirstLineIndent(24); // 设置首行缩进
        paragraph3.setLeading(0); // 行间距
        paragraph3.setSpacingBefore(0); // 设置段落上空白
        paragraph3.setSpacingAfter(0); // 设置段落下空白
        Paragraph paragraph4 = new Paragraph("建设单位(盖章)：", textfont);
        paragraph4.setAlignment(0); // 设置文字居中 0靠左 1，居中 2，靠右
        paragraph4.setIndentationLeft(12); // 设置左缩进
        paragraph4.setIndentationRight(12); // 设置右缩进
        paragraph4.setFirstLineIndent(24); // 设置首行缩进
        paragraph4.setLeading(0); // 行间距
        paragraph4.setSpacingBefore(75f); // 设置段落上空白
        paragraph4.setSpacingAfter(0); // 设置段落下空白
        Paragraph paragraph5 = new Paragraph("实发工资总金额：￥" + strssk2, textfont);
        paragraph5.setAlignment(2); // 设置文字居中 0靠左 1，居中 2，靠右
        paragraph5.setIndentationLeft(12); // 设置左缩进
        paragraph5.setIndentationRight(12); // 设置右缩进
        paragraph5.setFirstLineIndent(24); // 设置首行缩进
        paragraph5.setLeading(0); // 行间距
        paragraph5.setSpacingBefore(0); // 设置段落上空白
        paragraph5.setSpacingAfter(0); // 设置段落下空白
        Paragraph paragraph6 = new Paragraph("", textfont);
        paragraph6.setAlignment(0); // 设置文字居中 0靠左 1，居中 2，靠右
        paragraph6.setIndentationLeft(12); // 设置左缩进
        paragraph6.setIndentationRight(12); // 设置右缩进
        paragraph6.setFirstLineIndent(24); // 设置首行缩进
        paragraph6.setLeading(0); // 行间距
        paragraph6.setSpacingBefore(75f); // 设置段落上空白
        paragraph6.setSpacingAfter(15f); // 设置段落下空白

        PdfPTable table = createTable3(7);
        table.setWidthPercentage(100); // 宽度100%填充
        float[] columnWidths = { 1.2f, 2.5f, 3.5f, 2.5f, 2.5f, 2.5f, 2.5f };
        table.setWidths(columnWidths);
        // table.addCell(createCell("施工单位：(盖章)", headfont, Element.ALIGN_LEFT,
        // 7, false));
        // table.addCell(createCell2("应发工资总金额：", headfont, Element.ALIGN_LEFT,
        // 7, false));
        // table.addCell(createCell("建设单位(盖章)：", headfont, Element.ALIGN_LEFT,
        // 7, false));
        // table.addCell(createCell("实发工资总金额：", headfont, Element.ALIGN_LEFT, 7,
        // false));
        table.addCell(createCell("序号", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("姓名", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("身份证号", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("银行卡号", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("部门/班组", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("实发工资", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("领款签字人", keyfont, Element.ALIGN_CENTER));
        //序号
        Integer totalQuantity = 0;
        if (list.size() > 0) {
            for (EntityMap data : list) {
                Double payNet=MapUtils.getDoubleValue(data,"payNet");
                if(payNet!=null) {
                    //序号
                    table.addCell(myCreateCell(String.valueOf(totalQuantity + 1), textfont));
                    //姓名
                    table.addCell(myCreateCell(MapUtils.getString(data, "workerName", ""), textfont));
                    //身份证号
                    table.addCell(myCreateCell(MapUtils.getString(data, "idCard", ""), textfont));
                    //银行卡号
                    table.addCell(myCreateCell(MapUtils.getString(data, "payRollBankNumber", ""), textfont));
                    //
                    table.addCell(myCreateCell(MapUtils.getString(data, "departmentTeamName", ""), textfont));
                    //Double payNet = MapUtils.getDoubleValue(data, "payNet", 0d);
                    DecimalFormat df3 = new DecimalFormat("0.00");
                    String str3 = df3.format(payNet);
                    BigDecimal bigDecimalk3 = new BigDecimal(str3);
                    String strssk3 = bigDecimalk3.toPlainString();
                    // 实发工资payNet
                    table.addCell(myCreateCell(String.valueOf(strssk3), textfont));
                    // 领款待签字
                    table.addCell(myCreateCell("   ", textfont));
                    totalQuantity++;
                }
            }
        }
        document.add(paragraph);
        document.add(paragraph2);
        document.add(paragraph3);
        document.add(paragraph4);
        document.add(paragraph5);
        document.add(paragraph6);
        document.add(table);
    }

    /** --------------------------创建表格的方法end------------------- --------- */
    // 生成表格
    public static PdfPTable createTable2(int colNumber) {
        PdfPTable table = new PdfPTable(colNumber);
        try {
            table.setLockedWidth(true);
            //table.setTotalWidth(780);
            table.setTotalWidth(1100);
            table.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.getDefaultCell().setBorder(1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return table;
    }

    public static 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;
    }
    /**
     * 创建单元格（指定字体、水平居..、单元格跨x列合并、设置单元格内边距）
     *
     * @param value
     * @param font
     * @param align
     * @param colspan
     * @param boderFlag
     * @return
     */
    public static 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);// 标题下内容两个位置
        } else if (boderFlag) {
            cell.setBorder(0);
            cell.setPaddingTop(0.0f);
            cell.setPaddingBottom(15.0f);
        }
        return cell;
    }
    /**
     * 创建单元格(指定字体)
     * 固定高度40
     * @param value
     * @param font
     * @return
     */
    public static PdfPCell myCreateCell(String value, Font font) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPhrase(new Phrase(value, font));
        cell.setFixedHeight(40);
        return cell;
    }

    // 生成表格
    public static PdfPTable createTable3(int colNumber) {
        PdfPTable table = new PdfPTable(colNumber);
        try {
            table.setLockedWidth(true);
            table.setTotalWidth(520);
            table.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.getDefaultCell().setBorder(1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return table;
    }
}
