package com.sifang.modules.customer.pdf;

import com.itextpdf.text.*;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
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 com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.alioss.AliyunOSSClientUtil;
import com.sifang.modules.customer.entity.CrmAcceptingReport;
import com.sifang.modules.customer.entity.CustomerEntry;
import com.sifang.modules.customer.entity.CustomerEntryToExamine;
import com.sifang.modules.sunshine.SystemSetting.utils.BusinessException;
import com.sifang.modules.sunshine.SystemSetting.utils.StringUtil;
import com.sifang.modules.sys.common.utils.DateUtils;
import com.sifang.modules.sys.common.utils.IdGen;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.math.BigDecimal;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;

public class PdfReport {

    private static Logger logger = LoggerFactory.getLogger(PdfReport.class);

    private static String IMGURL;

    static {
        try {
            Configuration configuration = new PropertiesConfiguration("conf.properties");
            IMGURL = configuration.getString("img.domain");
            logger.info("IMGURL: {}", IMGURL);
        } catch (ConfigurationException e) {
            throw new RuntimeException(e);
        }
    }

    private static final String FILE_PATH_TEMPLATE = System.getProperty("java.io.tmpdir") + "/tempdf/%s";
    // main测试
    public static void main(String[] args) throws Exception {
        File file=null;
        try {

           // System.out.println(IMGURL+"png/20210615/9ab3c8f530434cff975166ba28b900ca/erwem.png");
            // 1.新建document对象
            //for(int i=0;i<4;i++){
            Image imglu = Image.getInstance(IMGURL +"energy_img/png/20231213/a40b8c2b3d564d87b637407938b96ed7/f7e4b2cd15f947cea2274f8d19a1871d.png");
            System.out.println(imglu);
            //}
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
          //  file.delete();
        }
    }

    public static void generTestPDf(File file){
        try {

            Document document = new Document(PageSize.A4);// 建立一个Document对象
            // 2.建立一个书写器(Writer)与document对象关联
            file.createNewFile();
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
            writer.setPageEvent(new Watermark("SUNGROW"));// 水印
            //  writer.setEncryption(null, null, 0xffffffff, PdfWriter.STANDARD_ENCRYPTION_128);
            //  writer.setPageEvent(new MyHeaderFooter());// 页眉/页脚
            // 3.打开文档
            document.open();
            document.addTitle("Title@PDF-Java");// 标题
            document.addAuthor("Author@umiz");// 作者
            document.addSubject("Subject@iText pdf sample");// 主题
            document.addKeywords("Keywords@iTextpdf");// 关键字
            document.addCreator("Creator@umiz`s");// 创建者

            // 4.向文档中添加内容
            new PdfReport().generatePDFD(document);
            // 5.关闭文档
            document.close();
            //}
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("generTestPDf--------:{}",e);
        }
    }

    /**
     * 将文件转换成byte数组
     * @return
     */
    public static byte[] File2byte(File tradeFile){
        byte[] buffer = null;
        try
        {
            FileInputStream fis = new FileInputStream(tradeFile);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] b = new byte[1024];
            int n;
            while ((n = fis.read(b)) != -1)
            {
                bos.write(b, 0, n);
            }
            fis.close();
            bos.close();
            buffer = bos.toByteArray();
        }catch (FileNotFoundException e){
            e.printStackTrace();
            logger.error("File2byte  -------FileNotFoundException -:{}",e);
        }catch (IOException e){
            e.printStackTrace();
            logger.error("File2byte  -------IOException:{}",e);
        }
        return buffer;
    }

    public static void createBusinessInfoPDF(OutputStream outputStream, CrmAcceptingReport report, CustomerEntry entry, CustomerEntryToExamine examine , Map<String,Object> map, java.util.List<Record> zhijialist){
        try {
            Document document = new Document(PageSize.A4);// 建立一个Document对象
            PdfWriter writer = PdfWriter.getInstance(document, outputStream);
//            writer.setPageEvent(new Watermark("SUNGROW"));// 水印
         //   writer.setPageEvent(new MyHeaderFooter());// 页眉/页脚
            // 3.打开文档
            document.open();
            document.addTitle("Title@PDF-Java");// 标题
            document.addAuthor("Author@umiz");// 作者
            document.addSubject("Subject@iText pdf sample");// 主题
            document.addKeywords("Keywords@iTextpdf");// 关键字
            document.addCreator("Creator@umiz`s");// 创建者
            // 4.向文档中添加内容
            new PdfReport().generatePDF(document,report,entry,examine,map,zhijialist);
            // 5.关闭文档
            document.close();

        }catch (Exception e){
            e.printStackTrace();
            logger.error("createBusinessInfoPDF  -------Exception:{}",e);
        }

    }

    // 定义全局的字体静态变量
    private static Font titlefont;
    private static Font headfont;
    private static Font keyfont;
    private static Font textfont;
    // 最大宽度
    private static int maxWidth = 492;
    // 静态代码块
    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();
        }
    }

    public void generatePDFD(Document document) throws Exception{
        PdfPTable table = createTable(new float[] {200, 150, 220, 142});
        table.addCell(createCell("学生信息列表：", keyfont,Element.ALIGN_LEFT,4,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));

        for(int i=0;i<5;i++){
            table.addCell(createCell("姓名"+i, textfont));
            table.addCell(createCell(i+15+"", textfont));
            table.addCell(createCell((i%2==0)?"男":"女", textfont));
            table.addCell(createCell("地址"+i, textfont));
        }
        document.add(table);
        PdfPTable tables = createTable(new float[] {200, 150, 220, 142});
        Image image1 = Image.getInstance("D:\\迅雷下载\\支架图片一.jpg");
        image1.setAlignment(Image.ALIGN_CENTER);
         //image.scalePercent(80); //依照比例缩放
        image1.scaleAbsolute(35,35);
        PdfPCell cell=createCell(image1, textfont,Element.ALIGN_CENTER,4,3);
        cell.disableBorderSide(15);
        cell.setBorder(0);
        tables.addCell(cell);
        document.add(tables);

        document.close();
    }

    private byte[] readIcon() {
        try (InputStream inputStream = this.getClass().getResource("/../../plug-in/static/img/login_logo.png").openStream()) {
            return IOUtils.toByteArray(inputStream);
        } catch (Exception e) {
            logger.error("读取logo失败", e);
            throw new BusinessException("读取logo失败");
        }
    }
    private String GdIMg ="prohibit_delete/46a1998.jpg";

    // 生成PDF文件
    //TODO 暂时屏蔽 验收报告需要重新调整 待处理
    public void generatePDF(Document document, CrmAcceptingReport report, CustomerEntry entry, CustomerEntryToExamine examine , Map<String,Object> map, java.util.List<Record> zhijialist) throws Exception {
        PdfPTable tables =  createTable(new float[] { 90, 90, 90, 90,});;//括号参数表示列,设置每列宽度比例
        tables.setTotalWidth(maxWidth);
        tables.setLockedWidth(true);
        tables.setHorizontalAlignment(Element.ALIGN_CENTER);
        tables.getDefaultCell().setBorder(0);
        tables.setHorizontalAlignment(Element.ALIGN_CENTER);//居中

        PdfPCell cellz=createCell("能辉光伏", textfont,Element.ALIGN_LEFT, 3, 2);
//        cellz.setRowspan(3);
        cellz.disableBorderSide(15);
        cellz.setBorder(0);
        tables.addCell(cellz);
        Image image1 = Image.getInstance(readIcon());
        image1.setAlignment(Image.ALIGN_LEFT);
        // image.scalePercent(80); //依照比例缩放
        image1.scaleAbsolute(30,30);
        PdfPCell cell=createCell(image1, textfont,Element.ALIGN_CENTER,1,2);
        cell.disableBorderSide(15);
        cell.setBorder(0);
        tables.addCell(cell);
/*        PdfPCell companyName = createCell("", textfont, Element.ALIGN_LEFT, 3, 1);
        companyName.disableBorderSide(15);
        companyName.setBorder(0);
        tables.addCell(companyName);*/
        document.add(tables);

        // 表格
        PdfPTable table = createTable(new float[] { 90, 90, 90, 90,90, 90, 90, 90});
        table.addCell(createCell("发电户号", headfont, Element.ALIGN_LEFT, 8));
        table.addCell(createCell("发电户号", textfont, Element.ALIGN_LEFT, 2));
        table.addCell(createCell(entry.getGeneratorNo(), textfont, Element.ALIGN_LEFT, 6));
        table.addCell(createCell("户用光伏电站验收报告", headfont, Element.ALIGN_LEFT, 8));
        PdfPCell cellone=createCell("一、电站基本信息", keyfont, Element.ALIGN_LEFT, 8);
        cellone.setBackgroundColor(new BaseColor(235,235,235));
        table.addCell(cellone);
        table.addCell(createCell("产品名称", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(entry.getProjectName(), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("产品编号", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(entry.getProjectCode(), textfont,Element.ALIGN_LEFT,2));
        table.addCell(createCell("项目名称", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(entry.getProvince()+entry.getArea()+entry.getStreet()+entry.getTenantName()+(entry.getActualCapacity().divide(new BigDecimal("1000")))+"KW光伏电站", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("电站编号", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(entry.getPowerStationCode(), textfont,Element.ALIGN_LEFT,2));

        table.addCell(createCell("代理商名称", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(entry.getTraderName(), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("代理商电话", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(entry.getTraderTel(), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("业主姓名", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(entry.getTenantName(), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("身份证号码", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(entry.getIdCode(), textfont, Element.ALIGN_LEFT,2));

        table.addCell(createCell("开户银行", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(entry.getBankName(), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("银行账号", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(entry.getBankCode(), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("联系电话", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(entry.getMobile(), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("安装方案", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(entry.getSchemeName(), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("安装地址", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(entry.getProvince()+entry.getCity()+entry.getArea()+entry.getStreet()+entry.getAddress(), textfont,Element.ALIGN_LEFT,6));

        PdfPCell celloneTwo=createCell("二、电站设备信息", keyfont, Element.ALIGN_LEFT, 8);
        celloneTwo.setBackgroundColor(new BaseColor(235,235,235));
        table.addCell(celloneTwo);
        table.addCell(createCell("组件品牌", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(String.valueOf(map.get("zujBrand")), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("组件规格", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(report.getComponentSpec()+"W", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("安装组件数量", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(report.getComponentNum().toString()+"块", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("安装组件容量", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(report.getCapacity().toString()+"W", textfont, Element.ALIGN_LEFT,2));

        table.addCell(createCell("逆变器1品牌", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(String.valueOf(map.get("nbqBrandOne")), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("逆变器1-SN码", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(String.valueOf(map.get("nbqSnOne")), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("逆变器1规格", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(String.valueOf(map.get("nbqSpecOne"))+map.get("nbqUnitOne"), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("通讯棒1-SN码", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(String.valueOf(map.get("snOne")), textfont, Element.ALIGN_LEFT,2));

        table.addCell(createCell("逆变器2品牌", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(map.get("nbqBrandTwo")!= null?String.valueOf(map.get("nbqBrandTwo")):"无", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("逆变器2-SN码", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(map.get("nbqSnTwo")!= null?String.valueOf(map.get("nbqSnTwo")):"无", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("逆变器2规格", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(map.get("nbqSpecTwo")!=null?String.valueOf(map.get("nbqSpecTwo"))+map.get("nbqUnitTwo"):"无", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("通讯棒2-SN码", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(map.get("snTwo")!=null?String.valueOf(map.get("snTwo")):"无", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("并网箱品牌", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(map.get("bwxBrand")==null?"无":String.valueOf(map.get("bwxBrand")), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("并网箱规格", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(map.get("bwxSpec")==null?"无":String.valueOf(map.get("bwxSpec")), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("并网箱数量", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(String.valueOf(map.get("bwxCOunt"))+(map.get("bwxUnit")==null?"":map.get("bwxUnit")), textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell("支架品牌", textfont, Element.ALIGN_LEFT,2));
        table.addCell(createCell(map.get("zjBrand")==null?"无":String.valueOf(map.get("zjBrand")), textfont, Element.ALIGN_LEFT,2));
        if(zhijialist != null){
            for(Record rd:zhijialist){
                table.addCell(createCell("支架规格", textfont, Element.ALIGN_LEFT,2,(int)map.get("zjCount")));
                table.addCell(createCell(rd.getStr("spec"), textfont, Element.ALIGN_LEFT,2));
                table.addCell(createCell("数量", textfont, Element.ALIGN_LEFT,2));
                table.addCell(createCell(String.valueOf(rd.getInt("amount"))+rd.getStr("unit"), textfont, Element.ALIGN_LEFT,2));
            }

        }



        PdfPCell celltwo=createCell("三、电站安装完成验收条款项", keyfont, Element.ALIGN_LEFT, 8);
        celltwo.setBackgroundColor(new BaseColor(235,235,235));
        table.addCell(celltwo);
//TODO 暂时屏蔽 待后面完善
//        String snStr=report.getZjSnImgs();
//        int i=2;
//        String[] arr=null;
//        if(StringUtil.isNotBlank(snStr)){
//            arr=snStr.split(",");
//            if(arr.length>3){
//                i=3;
//            }
//        }
//        logger.info(">>>>>ddi"+i);
//        table.addCell(createCell("1.设备信息照片", textfont, Element.ALIGN_LEFT, 2, (2+i)));
//        table.addCell(createCell("①序列号", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("②序列号", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("③组件铭牌照片", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getNbqPlateImg())?report.getNbqPlateImg():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getTxPlateImg())?report.getTxPlateImg():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZjPlateImg())?report.getZjPlateImg():GdIMg,2,1));
//        table.addCell(createCell("④组件SN", textfont, Element.ALIGN_LEFT,6)); //1-4张
//        if(arr!=null){
//             int k=3;
//             if(i==3){
//                 k=6;
//             }
//             for(int m=1;m<=k;m++){
//                 if(m>arr.length){
//                     table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//                     logger.info(">>>>>dd"+1);
//                 }else {
//                     String imgPath=arr[m-1];
//                     table.addCell(createImgCell(imgPath,2,1));
//                     logger.info(">>>>>dd"+2);
//                 }
//             }
//        }else{
//            table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//            table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//            table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//        }
//
//        String fgccStr=report.getSizeMeasureImgs();
//        int i2=2;
//        String[] fgccArr=null;
//        if(StringUtil.isNotBlank(fgccStr)){
//            fgccArr=fgccStr.split(",");
//            if(fgccArr.length>6){
//               i2=4;
//            }else if(fgccArr.length>3){
//                i2=3;
//            }
//        }
//        logger.info(".....支架及组件安装照片  rowspan:{}",10+i2);
//        table.addCell(createCell("2.支架及组件安装照片", textfont, Element.ALIGN_LEFT, 2, (10+i2)));
//        table.addCell(createCell("①膨胀螺栓", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("②基座安装固定", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("③底座防水", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZjImg1())?report.getZjImg1():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZjImg2())?report.getZjImg2():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZjImg3())?report.getZjImg3():GdIMg,2,1));
//        table.addCell(createCell("④支架基础距离房檐距离", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("⑤支架东向西拍摄", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("⑥支架西向东拍摄", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZjImg4())?report.getZjImg4():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZjImg5())?report.getZjImg5():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZjImg6())?report.getZjImg6():GdIMg,2,1));
//        table.addCell(createCell("⑦支架南向北拍摄", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("⑧支架北向南拍摄", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("⑨支架角度", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZjImg7())?report.getZjImg7():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZjImg8())?report.getZjImg8():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZjImg9())?report.getZjImg9():GdIMg,2,1));
//
//        table.addCell(createCell("⑩支架节点（斜支撑）", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("⑪支架距照片（南北）", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("⑫支架距照片（东西）", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getComponentImg1())?report.getComponentImg1():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getComponentImg2())?report.getComponentImg2():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getComponentImg3())?report.getComponentImg3():GdIMg,2,1));
//
//        table.addCell(createCell("⑬防风加固", textfont, Element.ALIGN_LEFT,6)); //1-3张
//        String ffjgStr=report.getComponentImg4();
//        logger.info(".....防风加固：{}",ffjgStr);
//        if(StringUtil.isNotBlank(ffjgStr)){
//            String[] ffjgarr=ffjgStr.split(",");
//            for(int m=1;m<=3;m++){
//                if(m>ffjgarr.length){
//                    table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//                    logger.info(">>>>>ff"+1);
//                }else {
//                    String imgPath=ffjgarr[m-1];
//                    table.addCell(createImgCell(imgPath,2,1));
//                    logger.info(">>>>>ff"+2);
//                }
//            }
//        }else{
//            table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//            table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//            table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//        }
//
//        table.addCell(createCell("⑭方管尺寸测量", textfont, Element.ALIGN_LEFT,6)); //9张
//        logger.info(".....方管尺寸测量：{}",fgccStr);
//        if(fgccArr!=null){
//            int k2=3;
//            if(i2==3){
//                k2=6;
//            }else if(i2==4){
//                k2=9;
//            }
//            logger.info(".....方管尺寸测量2");
//            for(int m=1;m<=k2;m++){
//                if(m>fgccArr.length){
//                    table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//                    logger.info(">>>>>fg"+1);
//                }else {
//                    String imgPath=fgccArr[m-1];
//                    table.addCell(createImgCell(imgPath,2,1));
//                    logger.info(">>>>>fg"+2);
//                }
//            }
//        }else{
//            logger.info(".....方管尺寸测量");
//            table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//            table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//            table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//        }
//
//        table.addCell(createCell("3.电气设备安装照片", textfont, Element.ALIGN_LEFT, 2, 4));
//        table.addCell(createCell("①并网箱、逆变器外部安装照片、接地引下线", textfont, Element.ALIGN_LEFT,2, 1));
//        table.addCell(createCell("②并网箱内部", textfont, Element.ALIGN_LEFT,2, 1));
//        table.addCell(createCell("③直流线缆保护", textfont, Element.ALIGN_LEFT,2, 1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getTotalImgs())?report.getTotalImgs():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getBwInnerImg())?report.getBwInnerImg():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getDqsbAnImgOne())?report.getDqsbAnImgOne():GdIMg,2,1));
//        table.addCell(createCell("④直流线缆固定", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getDqsbAnImgTwo())?report.getDqsbAnImgTwo():GdIMg,2,1));
//        table.addCell(createCell("", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("", textfont, Element.ALIGN_LEFT,2));
//
//        table.addCell(createCell("4.接地系统照片", textfont, Element.ALIGN_LEFT, 2, 4));
//        table.addCell(createCell("①引下线与支架连接点、南北坡接地连接点", textfont, Element.ALIGN_LEFT,4)); //2张
//        table.addCell(createCell("②组件边框接地", textfont, Element.ALIGN_LEFT,2));
//        if(StringUtil.isNotBlank(report.getZjJdImgs())){
//             String[] zjjdArr=report.getZjJdImgs().split(",");
//             if(zjjdArr.length==2){
//                 table.addCell(createImgCell(zjjdArr[0],2,1));
//                 table.addCell(createImgCell(zjjdArr[1],2,1));
//             }else{
//                 table.addCell(createImgCell(zjjdArr[0],2,1));
//                 table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//             }
//        }else{
//            table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//            table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//        }
//
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZujianJdImg())?report.getZujianJdImg():GdIMg,2,1));
//        table.addCell(createCell("③接地电阻", textfont, Element.ALIGN_LEFT, 6));//1-2张
//        if(StringUtil.isNotBlank(report.getGroundResistanceImgs())){
//            String[] zjjdArr=report.getGroundResistanceImgs().split(",");
//            if(zjjdArr.length==2){
//                table.addCell(createImgCell(zjjdArr[0],2,1));
//                table.addCell(createImgCell(zjjdArr[1],2,1));
//            }else{
//                table.addCell(createImgCell(zjjdArr[0],2,1));
//                table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//            }
//        }else{
//            table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//            table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//        }
//        table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
//
//
        String klImgs=report.getOpenWayVoltageImgs();
        int i3=0;
        String[] klArr=null;
        if(StringUtil.isNotBlank(klImgs)){
             klArr=klImgs.split(",");
            if(klArr.length>3){
                i3=1;
            }
        }
        table.addCell(createCell("5.调试记录照片", textfont, Element.ALIGN_LEFT, 2, (2+i3)));
        table.addCell(createCell("①开路电压", textfont, Element.ALIGN_LEFT,6)); //1-6张
        if(klArr!=null){
            int k3=3;
            if(i3==1){
               k3=6;
            }
            for(int m=1;m<=k3;m++){
                if(m>klArr.length){
                    table.addCell(createCell("",textfont, Element.ALIGN_LEFT,2));
                    logger.info(">>>>>kl"+1);
                }else {
                    String imgPath=klArr[m-1];
                    table.addCell(createImgCell(imgPath,2,1));
                    logger.info(">>>>>kl"+2);
                }
            }
        }else {
            table.addCell(createImgCell(GdIMg,6,1));
        }


        //TODO 暂时屏蔽 待后面完善
//        table.addCell(createCell("6.方阵安装完毕整体照片", textfont, Element.ALIGN_LEFT, 2,10));
//        table.addCell(createCell("①东向西航拍", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("②西向东航拍", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("③南向北航拍", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getDirectionAirImg1())?report.getDirectionAirImg1():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getDirectionAirImg2())?report.getDirectionAirImg2():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getDirectionAirImg3())?report.getDirectionAirImg3():GdIMg,2,1));
//
//        table.addCell(createCell("④北向南航拍", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("⑤组件近景", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("⑥组件角度", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getDirectionAirImg4())?report.getDirectionAirImg4():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZjNearImg())?report.getZjNearImg():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZjAngleImg())?report.getZjAngleImg():GdIMg,2,1));
//
//        table.addCell(createCell("⑦檩条出组件照片", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("⑧水槽照片", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("⑨中压固定照片", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getZjItemImg())?report.getZjItemImg():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getWaterChannelImg())?report.getWaterChannelImg():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getMediumFixImg())?report.getMediumFixImg():GdIMg,2,1));
//
//
//        table.addCell(createCell("⑩安全警示牌", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("⑪现场安全交底文件", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("⑫现场交底照片", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getSafetyWarningImg())?report.getSafetyWarningImg():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getSafetyDiscloseDocImg())?report.getSafetyDiscloseDocImg():GdIMg,2,1));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getDiscloseDocImg())?report.getDiscloseDocImg():GdIMg,2,1));
//
//        table.addCell(createCell("⑬记录表", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createImgCell(StringUtil.isNotBlank(report.getRecordDocImg())?report.getRecordDocImg():GdIMg,2,1));
//        table.addCell(createCell("", textfont, Element.ALIGN_LEFT,2));
//        table.addCell(createCell("", textfont, Element.ALIGN_LEFT,2));


        PdfPCell cellthree=createCell("四、电站并网验收条款项", textfont, Element.ALIGN_LEFT, 8);
        cellthree.setBackgroundColor(new BaseColor(235,235,235));
        table.addCell(cellthree);
        table.addCell(createCell("①近3天发电量", textfont, Element.ALIGN_LEFT, 4, 1));
        table.addCell(createCell("②补充", textfont, Element.ALIGN_LEFT, 4, 1));
        table.addCell(createImgCell(report.getYxImg(), 4, 1));
        table.addCell(createImgCell(StringUtil.isNotBlank(report.getGebImg())?report.getGebImg():GdIMg, 4, 1));

        PdfPCell cellfour =createCell("五、验收结论", textfont, Element.ALIGN_LEFT, 8);
        cellfour.setBackgroundColor(new BaseColor(235,235,235));
        table.addCell(cellfour);

        table.addCell(createCell("踏勘设计\n审核意见", textfont, Element.ALIGN_LEFT, 1, 3));
        table.addCell(createCell("能辉光伏\n技术支持工程师", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getExamineOne(), textfont, Element.ALIGN_LEFT, 2, 1));
        table.addCell(createCell("初审人", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getOperatorOne(), textfont, Element.ALIGN_LEFT));
        table.addCell(createCell("审核时间", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(DateUtils.formatDateTime(examine.getExamineTime()), textfont, Element.ALIGN_LEFT));

        table.addCell(createCell("能辉光伏\n技术部负责人", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getExamineTwo(), textfont, Element.ALIGN_LEFT, 2, 1));
        table.addCell(createCell("复审人", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getOperatorTwo(), textfont, Element.ALIGN_LEFT));
        table.addCell(createCell("审核时间", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(DateUtils.formatDateTime(examine.getExamineTimeTwo()), textfont, Element.ALIGN_LEFT));

        table.addCell(createCell("资方", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getExamineThree(), textfont, Element.ALIGN_LEFT, 2, 1));
        table.addCell(createCell("审核人", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getOperatorThree(), textfont, Element.ALIGN_LEFT));
        table.addCell(createCell("审核时间", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(DateUtils.formatDateTime(examine.getExamineTimeThree()), textfont, Element.ALIGN_LEFT));


        table.addCell(createCell("完工验收\n审核意见", textfont, Element.ALIGN_LEFT, 1, 3));
        table.addCell(createCell("能辉光伏\n质量工程师", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getExamineFour(), textfont, Element.ALIGN_LEFT, 2, 1));
        table.addCell(createCell("初审人", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getOperatorFour(), textfont, Element.ALIGN_LEFT));
        table.addCell(createCell("审核时间", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(DateUtils.formatDateTime(examine.getExamineTimeFour()), textfont, Element.ALIGN_LEFT));

        table.addCell(createCell("能辉光伏\n工程部负责人", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getExamineFive(), textfont, Element.ALIGN_LEFT, 2, 1));
        table.addCell(createCell("复审人", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getOperatorFive(), textfont, Element.ALIGN_LEFT));
        table.addCell(createCell("审核时间", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(DateUtils.formatDateTime(examine.getExamineTimeFive()), textfont, Element.ALIGN_LEFT));

        table.addCell(createCell("资方", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getExamineSix(), textfont, Element.ALIGN_LEFT, 2, 1));
        table.addCell(createCell("审核人", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getOperatorSix(), textfont, Element.ALIGN_LEFT));
        table.addCell(createCell("审核时间", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(DateUtils.formatDateTime(examine.getExamineTimeSix()), textfont, Element.ALIGN_LEFT));


        table.addCell(createCell("并网验收\n审核意见", textfont, Element.ALIGN_LEFT, 1, 3));
        table.addCell(createCell("能辉光伏\n质量工程师", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getExamineSeven(), textfont, Element.ALIGN_LEFT, 2, 1));
        table.addCell(createCell("初审人", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getOperatorSeven(), textfont, Element.ALIGN_LEFT));
        table.addCell(createCell("审核时间", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(DateUtils.formatDateTime(examine.getExamineTimeSeven()), textfont, Element.ALIGN_LEFT));

        table.addCell(createCell("能辉光伏\n工程部负责人", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getExamineEight(), textfont, Element.ALIGN_LEFT, 2, 1));
        table.addCell(createCell("复审人", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getOperatorEight(), textfont, Element.ALIGN_LEFT));
        table.addCell(createCell("审核时间", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(DateUtils.formatDateTime(examine.getExamineTimeEight()), textfont, Element.ALIGN_LEFT));

        table.addCell(createCell("资方", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getExamineNine(), textfont, Element.ALIGN_LEFT, 2, 1));
        table.addCell(createCell("审核人", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(examine.getOperatorNine(), textfont, Element.ALIGN_LEFT));
        table.addCell(createCell("审核时间", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(DateUtils.formatDateTime(examine.getExamineTimeNine()), textfont, Element.ALIGN_LEFT));

        table.addCell(createCell("终验结论", textfont, Element.ALIGN_LEFT, 1, 1));
        if("a".equals(entry.getStatus())){
            table.addCell(createCell("已完成验收", textfont, Element.ALIGN_LEFT, 3, 1));
        }else{
            table.addCell(createCell("", textfont, Element.ALIGN_LEFT, 3, 1));
        }

        table.addCell(createCell("验收时间", textfont, Element.ALIGN_LEFT, 1, 1));
        if("a".equals(entry.getStatus())){
            table.addCell(createCell(DateUtils.formatDateTime(examine.getExamineTimeNine()), textfont, Element.ALIGN_LEFT, 3, 1));
        }else{
            table.addCell(createCell("", textfont, Element.ALIGN_LEFT, 3, 1));
        }


      /*  table.addCell(createCell(ObjectUtils.defaultIfNull(report.getMergeConclusion(), ""), textfont, Element.ALIGN_LEFT, 3));
        table.addCell(createCell("终验结论", textfont, Element.ALIGN_LEFT));
        table.addCell(createCell(ObjectUtils.defaultIfNull(report.getFinalConclusion(), ""), textfont, Element.ALIGN_LEFT, 3));
        */
        document.add(table);

    }

    private PdfPCell createImgCell(String img) throws IOException, BadElementException {
        return createImgCell(img, 1, 1);
    }

    private PdfPCell createImgCell(String img, int colspan, int rowspan)  {
        if (StrKit.isBlank(img)) {
            return createCell("", textfont);
        }
        try {
            logger.info(">>>>>>>>>>>>createImgCell img:{},ims:{} ",img,IMGURL);
            Image imglu = Image.getInstance(IMGURL + URLEncoder.encode(img, "utf-8"));
            imglu.scaleAbsolute(90, 90);
            PdfPCell cellu = createCell(imglu, textfont, 1, colspan, rowspan);
            cellu.disableBorderSide(1);
            cellu.setFixedHeight(160);
            cellu.setHorizontalAlignment(Element.ALIGN_CENTER);
            return cellu;
        }catch (Exception e){
            logger.error("createImgCell {} ",e);
        }
        return  null;
    }

    /**
     * 将BufferedImage转换为InputStream
     * @param image
     * @return
     */
    public static InputStream bufferedImageToInputStream(BufferedImage image){
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        try {
            ImageIO.write(image, "png", os);
            InputStream input = new ByteArrayInputStream(os.toByteArray());
            return input;
        } catch (IOException e) {
            logger.error("提示:",e);
        }
        return null;
    }
    /**
     *
     * @param inputStream
     * @return 将InputStream转化为Image
     * @throws Exception
     */
    public static Image getImageFromInputStream(InputStream inputStream) throws Exception {
        int n;
        byte[] buffer = new byte[4096];
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        while (-1 != (n = inputStream.read(buffer))) {
            output.write(buffer, 0, n);
        }
        Image image = Image.getInstance(output.toByteArray());
        return image;
    }

    public  boolean oddOrEven(int a) {
        if (a % 2 != 0) {
            return true;
        } else {
            return false;
        }
    }

/**------------------------创建表格单元格的方法start----------------------------*/
    /**
     * 创建单元格(指定字体)
     * @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
     * @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;
    }
    /**
     * 创建单元格（指定字体、水平居..、单元格跨x列合并）
     * @param value
     * @param font
     * @param align
     * @param colspan
     * @return
     */
    private PdfPCell createCell(String value, Font font, int align, int colspan) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell.setHorizontalAlignment(align);
        cell.setColspan(colspan);
        cell.setPhrase(new Phrase(value, font));
        return cell;
    }

    private PdfPCell createCell(String value, Font font, int align, int colspan, int rowspan) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setColspan(colspan);
        cell.setRowspan(rowspan);
        cell.setPhrase(new Phrase(value, font));
        return cell;
    }
    /**
     * 创建单元格（指定字体、水平居..、单元格跨x列合并、设置单元格内边距）
     * @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_BOTTOM);
        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;
    }
    /**
     * 创建单元格（指定字体、水平..、边框宽度：0表示无边框、内边距）
     * @param image
     * @param font
     * @param align
     * @param colspan
     * @param rowspan
     * @return
     */
    public PdfPCell createCell(Image image, Font font, int align, int colspan,int rowspan) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setColspan(colspan);
        cell.setRowspan(rowspan);
        cell.setFixedHeight(rowspan*25f);
        cell.setImage(image);
        // cell.setPhrase(new Phrase(new Chunk(image, 0, 0,false)));
        return cell;

    }

    /**
     * 创建单元格（指定字体、水平..、边框宽度：0表示无边框、内边距）
     * @param value
     * @param font
     * @param align
     * @param borderWidth
     * @param paddingSize
     * @param flag
     * @return
     */
    public PdfPCell createCell(String value, Font font, int align, float[] borderWidth, float[] paddingSize, boolean flag) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setPhrase(new Phrase(value, font));
        cell.setBorderWidthLeft(borderWidth[0]);
        cell.setBorderWidthRight(borderWidth[1]);
        cell.setBorderWidthTop(borderWidth[2]);
        cell.setBorderWidthBottom(borderWidth[3]);
        cell.setPaddingTop(paddingSize[0]);
        cell.setPaddingBottom(paddingSize[1]);
        if (flag) {
            cell.setColspan(2);
        }
        return cell;
    }
/**------------------------创建表格单元格的方法end----------------------------*/


/**--------------------------创建表格的方法start------------------- ---------*/
    /**
     * 创建默认列宽，指定列数、水平(居中、右、左)的表格
     * @param colNumber
     * @param align
     * @return
     */
    public PdfPTable createTable(int colNumber, int align) {
        PdfPTable table = new PdfPTable(colNumber);
        try {
            table.setTotalWidth(maxWidth);
            table.setLockedWidth(true);
            table.setHorizontalAlignment(align);
            table.getDefaultCell().setBorder(1);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("createTable    -------Exception:{}",e);
        }
        return table;
    }
    /**
     * 创建指定列宽、列数的表格
     * @param widths
     * @return
     */
    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;
    }
    /**
     * 创建空白的表格
     * @return
     */
    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;
    }
/**--------------------------创建表格的方法end------------------- ---------*/

}
