导出pdf并存放到zip中

导出pdf并存放到zip中

controller
    
@UBA(module = "发现问题单", action = "导出PDF", channel = OperatorType.Page)
    @PostMapping("/exportPdf")
    public AjaxResult exportPdf(HttpServletResponse response,@RequestBody ProblemFindingVo problemFindingVo) throws Exception {
        try {
            problemFindingService.exportPdf(response,problemFindingVo);
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            return error("导出pdf异常:" + e.getMessage());
        }
    }
service
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cgnpc.cud.boot.autoconfigure.aep.AepProperties;
import com.cgnpc.cud.core.common.util.CollectionUtils;
import com.cgnpc.cud.core.common.util.DateUtils;
import com.cgnpc.cud.core.common.util.StringUtils;
import com.cgnpc.cud.utils.UUIDUtil;
import com.cgnpc.cud.utils.text.StringUtil;
import com.cgnpc.framework.exception.BusinessException;
import com.cgnpc.framework.service.IEmailCenterService;
import com.cgnpc.framework.userinfo.CurrentUser;
import com.cgnpc.framework.utils.CgnHeader;
import com.cgnpc.imsqs.app.util.AppUser;
import com.cgnpc.imsqs.comm.application.AttachApplication;
import com.cgnpc.imsqs.comm.domain.Attach;
import com.cgnpc.imsqs.comm.mapper.AttachMapper;
import com.cgnpc.imsqs.integratedManagement.service.PersonnelService;
import com.cgnpc.imsqs.recordReport.domain.*;
import com.cgnpc.imsqs.recordReport.mapper.*;
import com.cgnpc.imsqs.recordReport.service.ProblemFindingService;
import com.cgnpc.imsqs.recordReport.vo.MemoVo;
import com.cgnpc.imsqs.recordReport.vo.NotOverdueVo;
import com.cgnpc.imsqs.recordReport.vo.ObservationListVO;
import com.cgnpc.imsqs.recordReport.vo.ProblemFindingTrackingVo;
import com.cgnpc.imsqs.recordReport.vo.ProblemFindingVo;
import com.cgnpc.imsqs.supervisionTask.mapper.ContractMapper;
import com.cgnpc.imsqs.supervisionTask.mapper.PersonnelRoleMapper;
import com.cgnpc.imsqs.supervisionTask.service.IContractSupplierInfoService;
import com.cgnpc.imsqs.supplierMgnt.service.ISupplierPmService;
import com.cgnpc.imsqs.systemManage.domain.TPresentationTrackFrequency;
import com.cgnpc.imsqs.systemManage.service.ISupervisePlanDictService;
import com.cgnpc.imsqs.systemManage.service.ITPresentationTrackFrequencyService;
import com.cgnpc.imsqs.systemManage.vo.SupervisePlanDictVo;
import com.cgnpc.imsqs.utils.CommConstants;
import com.cgnpc.imsqs.utils.CommonMethods;
import com.cgnpc.imsqs.utils.DateFormatUtil;
import com.cgnpc.imsqs.utils.EasyExcelUtil;
import com.cgnpc.imsqs.utils.PrmsUtils;
import com.cgnpc.imsqs.utils.SnowflakeIdWorker;
import com.cgnpc.imsqs.utils.TokenUtil;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;

import cn.com.cgnpc.aep.bizcenter.appcenter.sdk.client.RestClient;
import cn.com.cgnpc.aep.bizcenter.appcenter.sdk.config.Constants;
import cn.com.cgnpc.aep.bizcenter.appcenter.sdk.exception.CgnApiException;
import cn.com.cgnpc.aep.bizcenter.appcenter.sdk.result.ApiResult;
import cn.com.cgnpc.aep.bizcenter.appcenter.sdk.vo.CgnRequestHeader;
import cn.com.cgnpc.aep.bizcenter.filecenter.api.vo.UploadBaseInfoVO;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;

@Override
    public void exportPdf(HttpServletResponse response,ProblemFindingVo problemFindingVo) throws Exception {
        String[] ids = problemFindingVo.getIds();
        if (ids == null || ids.length == 0) {
            throw new BusinessException("请先选择要导出pdf的数据");
        }
        List<File> fileList = new ArrayList<>();
        for (String id : ids) {
            ProblemFinding problemFinding = this.getById(id);
            String path = this.createPdf(problemFinding);
            fileList.add(new File(path));
        }
        response.setContentType("application/octet-stream;charset=UTF-8");
        response.setCharacterEncoding("utf-8");
        String fileName = DateUtils.parseDateToStr("yyyyMMddHHmmss", new Date()) + ".zip";
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        OutputStream os = response.getOutputStream();
        commonMethods.toZip(fileList, os);
        for (File file : fileList) {
            if (file.exists()) {
                file.delete();
            }
        }
    }
    
 private String createPdf(ProblemFinding problemFinding) throws Exception {
        String fileName = problemFinding.getProblemCode() + ".pdf";
        Document document = new Document(PageSize.A4);    //纵向分布
        String path = "src/main/resources/pdf/";        //绝对路径
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        File pdfFile = new File(path, fileName);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(pdfFile));

        document.open();
        this.createTable(document, problemFinding);
        document.close();
        return pdfFile.getAbsolutePath();
    }

    private void createTable(Document document, ProblemFinding problemFinding) throws Exception {
        commonMethods.createPDFCommonHeader(document, "设备监造发现问题");
        
        String projectName = "";
        if(!StringUtils.isEmpty(problemFinding.getProjectCode())){
        	SupervisePlanDictVo supervisePlanDictVo = new SupervisePlanDictVo();
            supervisePlanDictVo.setCode("PROJECT");
            List<SupervisePlanDictVo> projectList = supervisePlanDictService.getListByFolderCode(supervisePlanDictVo);
            for (int i = 0; i < projectList.size(); i++) {
                SupervisePlanDictVo supervisePlan = projectList.get(i);
                if (problemFinding.getProjectCode().equals(supervisePlan.getCode())) {
                	projectName = supervisePlan.getCode() + "("+supervisePlan.getName() +")";
                }
            }
        }
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font font = new Font(bfChinese, 8, Font.NORMAL, BaseColor.BLACK);
        commonMethods.getTable("项目:"+ projectName,"合同订单编号:" + commonMethods.converString(problemFinding.getContractCode()),font,document);
        commonMethods.getTable("机组:"+ commonMethods.converString(problemFinding.getMachineGroup()),"采购包编号:"+ commonMethods.converString(problemFinding.getPurchasePackage()),font,document);
        commonMethods.getTable("设备:"+commonMethods.converString(problemFinding.getEquipment()), "部件:" + commonMethods.converString(problemFinding.getParts()),font, document);
        commonMethods.getTable("供应商:"+ commonMethods.converString(problemFinding.getSupplier()),"问题编号:"+commonMethods.converString(problemFinding.getProblemCode()), font, document);
        commonMethods.getTable("片区:" + commonMethods.converString(problemFinding.getAreaCode()),"创建人:"+ commonMethods.converString(problemFinding.getCreateUserName()),font, document);
        String submitDate = "";
        if(!"0".equals(problemFinding.getStatus())){//草稿
    		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        	if(problemFinding.getSubmitDate() != null){
        		submitDate = format.format(problemFinding.getSubmitDate());
        	}else{
        		submitDate = format.format(problemFinding.getCreateTime());
        	}
        }
        commonMethods.getTable("发现日期:"+commonMethods.converString(problemFinding.getDiscoverDate()), "发布日期:"+submitDate,font, document);
        //commonMethods.getTable("创建人:"+commonMethods.converString(problemFinding.getRecipients()),"创建日期:"+commonMethods.converString(problemFinding.getCreationDate()),font, document);
        //String whetherForgeCorrelation = StringUtils.isEmpty(problemFinding.getWhetherForgeCorrelation())?"":"1".equals(problemFinding.getWhetherForgeCorrelation())?"是":"否";
        //String whetherPreventiveProblem = StringUtils.isEmpty(problemFinding.getWhetherPreventiveProblem())?"":"1".equals(problemFinding.getWhetherPreventiveProblem())?"是":"否";
        //commonMethods.getTable("是否造假相关:"+ whetherForgeCorrelation,"是否预防性问题:"+ whetherPreventiveProblem,font,document);
        //commonMethods.getTableSpan( 20,"预防问题分类:" + commonMethods.converString(problemFinding.getPreventiveProblemType()),font, document);
        String problemDescription = PrmsUtils.delHTMLTag(problemFinding.getProblemDescription());
        problemDescription = problemDescription + "\n   (以下无内容)\n\n";
        commonMethods.getTableSpan(120,"问题描述:" + problemDescription, font, document,430);
        List<Map<String, Object>> attach = this.queryAttachListByMainTableId(problemFinding.getId());
        List<String> fileNames = new ArrayList<>();
        for (Map<String, Object> map : attach) {
            if (!StringUtil.isEmpty((String)map.get("fileName"))) {
                String name = map.get("fileName") + "";
                fileNames.add(name);
            }
        }
        commonMethods.getTableSpan(20,"附件:\n"+ String.join(";\n",fileNames), font, document);

        //commonMethods.createPDFCommonFooter(document,problemFinding.getCreateUserName());
    }
公共导出PDF类
package com.cgnpc.imsqs.utils;

import cn.com.cgnpc.aep.bizcenter.appcenter.sdk.result.ApiResult;
import cn.com.cgnpc.aep.bizcenter.email.vo.SendEmails;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cgnpc.cud.core.common.util.DateUtils;
import com.cgnpc.framework.exception.BusinessException;
import com.cgnpc.framework.service.IEmailCenterService;
import com.cgnpc.framework.userinfo.CurrentUser;
import com.cgnpc.imsqs.comm.application.StaffsApplication;
import com.cgnpc.imsqs.comm.application.UpLoadApplication;
import com.cgnpc.imsqs.comm.domain.Attach;
import com.cgnpc.imsqs.comm.mapper.AttachMapper;
import com.cgnpc.imsqs.superviseExecution.domain.ManufacturingClassNcr;
import com.cgnpc.imsqs.superviseExecution.mapper.ManufacturingClassNcrMapper;
import com.cgnpc.imsqs.supervisePlanning.domain.*;
import com.cgnpc.imsqs.supervisePlanning.mapper.*;
import com.cgnpc.imsqs.supervisePlanning.service.IQualityPlanDetailsService;
import com.cgnpc.imsqs.supervisePlanning.vo.*;
import com.cgnpc.imsqs.supervisionTask.domain.Contract;
import com.cgnpc.imsqs.supervisionTask.domain.PersonnelRole;
import com.cgnpc.imsqs.supervisionTask.mapper.ContractMapper;
import com.cgnpc.imsqs.supervisionTask.mapper.PersonnelRoleMapper;
import com.cgnpc.imsqs.supplierMgnt.domain.SupplierInfo;
import com.cgnpc.imsqs.supplierMgnt.domain.SupplierPm;
import com.cgnpc.imsqs.supplierMgnt.service.ISupplierInfoService;
import com.cgnpc.imsqs.supplierMgnt.service.ISupplierPmService;
import com.cgnpc.imsqs.systemManage.service.ISupervisePlanDictService;
import com.cgnpc.imsqs.systemManage.vo.SupervisePlanDictVo;
import com.google.common.base.CharMatcher;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;


@Component
public class CommonMethods {

    @Autowired
    private WitnessPointManageMapper witnessPointManageMapper;

    @Autowired
    private QualityDetailsProcessMapper qualityDetailsProcessMapper;

    @Autowired
    private IQualityPlanDetailsService qualityPlanDetailsService;

    @Autowired
    WitnessPointMangeRelevanceMapper witnessPointMangeRelevanceMapper;
    @Autowired
    WitnessPointExperiencdFeedbackOpMapper witnessPointExperiencdFeedbackOpMapper;
    @Autowired
    WitnessPointSupervisePointOpMapper witnessPointSupervisePointOpMapper;
    @Autowired
    WitnessPointSupervisePointDetailsOpMapper witnessPointSupervisePointDetailsOpMapper;
    @Autowired
    WitnessPointOpAttachMapper witnessPointOpAttachMapper;
    @Autowired
    QualityProcessConversionMapper qualityProcessConversionMapper;
    @Autowired
    RemindPeopleMapper remindPeopleMapper;
    @Autowired
    ContractMapper contractMapper;

    @Autowired
    private StaffsApplication staffsApplication;
    @Autowired
    IEmailCenterService iEmailCenterService;
    @Autowired
    ISupplierPmService supplierPmService;
    @Autowired
    ISupplierInfoService supplierService;

    @Autowired
    QualityPlanInfoMapper qualityPlanInfoMapper;
    @Autowired
    PersonnelRoleMapper personnelRoleMapper;

    @Autowired
    private AttachMapper attachMapper;

    @Autowired
    WitnessVanishingPointMapper witnessVanishingPointMapper;
    @Autowired
    private ISupervisePlanDictService supervisePlanDictService;
    @Autowired
    private ManufacturingClassNcrMapper manufacturingClassNcrMapper;

    @Autowired
    private UpLoadApplication upLoadApplication;

    private static final int BUFFER_SIZE = 40 * 1024;


    /**
     * 一组文件打压缩包
     * @param srcFiles
     * @param out
     * @return
     * @throws Exception
     */
    public static ZipOutputStream toZip(List<File> srcFiles, OutputStream out) throws Exception {
        long start = System.currentTimeMillis();
        ZipOutputStream zos = null;
        try {
            zos = new ZipOutputStream(out);
            for (File srcFile : srcFiles) {
                byte[] buf = new byte[BUFFER_SIZE];
                zos.putNextEntry(new ZipEntry(srcFile.getName()));
                int len;
                FileInputStream in = new FileInputStream(srcFile);
                while ((len = in.read(buf)) != -1) {
                    zos.write(buf, 0, len);
                }
                zos.closeEntry();
                in.close();
            }
            long end = System.currentTimeMillis();
            System.out.println("压缩完成,耗时:" + (end - start) + " ms");
        } catch (Exception e) {
            throw new RuntimeException("zip error from ZipUtils", e);
        } finally {
            if (zos != null) {
                try {
                    zos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return zos;
    }

    /**
     * 创建PDF通用头部
     * @param document
     * @param name
     * @throws Exception
     */
    public Document createPDFCommonHeader(Document document, String name) throws Exception {
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font normal1 = new Font(bfChinese, 18, Font.BOLD, BaseColor.BLACK);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(80);

        PdfPCell cel1 = new PdfPCell();
        cel1.setBorder(0);
        cel1.setFixedHeight(40);
        String imagePath = this.getClass().getClassLoader().getResource("").getPath() + "/image/cgn_logo_new.png";
        Image tubiao = Image.getInstance(imagePath);
        tubiao.scaleAbsolute(40, 40);
        cel1.setImage(tubiao);
        table.addCell(cel1);

        PdfPCell c1 = new PdfPCell();
        c1.setFixedHeight(40);
        c1.setBorder(0);
        c1.setPaddingTop(8f);
        Paragraph p1 = new Paragraph(name, normal1);
        p1.setAlignment(Element.ALIGN_CENTER);
        c1.addElement(p1);
        table.addCell(c1);

        document.add(table);
        return document;
    }

    public Document createPDFCommonFooter(Document document, String createUserName) throws Exception {
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font normal = new Font(bfChinese, 8, Font.NORMAL, BaseColor.BLACK);
        Font normal1 = new Font(bfChinese, 15, Font.BOLD, BaseColor.BLACK);
        PdfPTable tt1 = new PdfPTable(1);
        tt1.setWidthPercentage(80);

        PdfPCell ccc1 = new PdfPCell();
        ccc1.setLeft(1f);
        ccc1.setFixedHeight(45);
        ccc1.setPaddingRight(15f);
        ccc1.setPaddingTop(0f);
        Paragraph ppp1 = new Paragraph(createUserName, normal1);
        ppp1.setAlignment(Element.ALIGN_RIGHT);
        ccc1.addElement(ppp1);
        tt1.addCell(ccc1);

        PdfPCell ccc2 = new PdfPCell();
        //ccc2.setLeft(1f);
        ccc2.setPaddingRight(15f);
        ccc2.setPaddingTop(-18f);
        Paragraph ppp2 = new Paragraph("中广核工程有限公司设备监造代表", normal);
        ppp2.setAlignment(Element.ALIGN_RIGHT);
        ccc2.addElement(ppp2);
        tt1.addCell(ccc2);

        document.add(tt1);
        return document;
    }

    /**
     * 导出pdf-创建pdf-添加一行表格,
     * 表格中添加两个单元格,单元格中添加参数1、参数2,
     * 参数以字体normal展示,
     * 元素左对齐,
     * 表格80%宽度
     * 参数填充高度18像素
     * @param param1
     * @param param2
     * @param normal
     * @param document
     * @throws DocumentException
     */
    public void getTable(String param1, String param2, Font normal, Document document) throws DocumentException {

        float minimumHeight = 18f;
        PdfPTable table1 = new PdfPTable(2);
        table1.setWidthPercentage(80);

        PdfPCell cell1 = new PdfPCell();
        cell1.setCalculatedHeight(100f);
        cell1.setMinimumHeight(minimumHeight);
        cell1.setLeft(1f);
        cell1.setNoWrap(false);
        Paragraph paragraph1 = new Paragraph(param1, normal);
        paragraph1.setAlignment(Element.ALIGN_LEFT);
        cell1.addElement(paragraph1);
        table1.addCell(cell1);

        PdfPCell cell2 = new PdfPCell();
        cell2.setCalculatedHeight(100f);
        cell2.setMinimumHeight(minimumHeight);
        cell2.setLeft(1f);
        cell2.setNoWrap(false);
        Paragraph paragraph2 = new Paragraph(param2, normal);
        paragraph2.setAlignment(Element.ALIGN_LEFT);
        cell2.addElement(paragraph2);
        table1.addCell(cell2);

        document.add(table1);
    }

    /**
     * 导出pdf-创建pdf-添加一行表格,表格中添加一个单元格
     * @param height
     * @param param1
     * @param normal
     * @param document
     * @throws DocumentException
     */
    public void getTableSpan(int height, String param1, Font normal, Document document) throws DocumentException {
        getTableSpan(height, param1, normal, document, 20f);
    }

    /**
     * 导出pdf-创建pdf-添加一行表格,表格中添加一个单元格(自定义table高度)
     * @param height
     * @param param1
     * @param normal
     * @param document
     * @throws DocumentException
     */
    public void getTableSpan(int height, String param1, Font normal, Document document,float minimumHeight) throws DocumentException {
        PdfPTable table1 = new PdfPTable(1);
        table1.setWidthPercentage(80);
        //跨页
        table1.setSplitLate(false);
        table1.setSplitRows(true);
        PdfPCell cell1 = new PdfPCell();
        cell1.setFixedHeight(height);
        //cell1.setBorder(0);
        Paragraph paragraph1 = new Paragraph(param1, normal);
        paragraph1.setAlignment(Element.ALIGN_LEFT);
        cell1.addElement(paragraph1);
        cell1.setMinimumHeight(minimumHeight);
        table1.addCell(cell1);
        document.add(table1);
    }

    public void getTableSpan2(int height, String param1, Font normal, Document document) throws DocumentException {
        PdfPTable table1 = new PdfPTable(1);
        table1.setWidthPercentage(80);
        //跨页
        table1.setSplitLate(false);
        table1.setSplitRows(true);
        PdfPCell cell1 = new PdfPCell();
        cell1.setFixedHeight(height);
        cell1.disableBorderSide(1);
//        cell1.setBorder(0);
        Paragraph paragraph1 = new Paragraph(param1, normal);
        paragraph1.setAlignment(Element.ALIGN_LEFT);
        cell1.addElement(paragraph1);
        cell1.setMinimumHeight(20f);
        table1.addCell(cell1);

        document.add(table1);
    }

    public String getTableNA(String param1){
        if(StringUtils.isEmpty(param1)){
            param1 = "NA";
        }
        return param1;
    }
    public void getTable(Font normal, Document document,String value1,String value2,String value3,String value4)
            throws DocumentException,  IOException {
        PdfPTable table = new PdfPTable(2);
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font font = new Font(bfChinese, 8, Font.NORMAL, BaseColor.BLACK);
        table.setWidthPercentage(80);

        PdfPCell c2 = new PdfPCell();
        c2.setFixedHeight(40);
        c2.setLeft(1f);
        c2.setMinimumHeight(25f);
        c2.setPaddingBottom(5f);
        Phrase address = new Phrase();
        address.add(new Paragraph(" ", normal));
        Paragraph p1 = new Paragraph(value1, font);
        p1.setAlignment(Element.ALIGN_LEFT);
        address.add(p1);
        address.add(Chunk.NEWLINE);
        address.add(new Paragraph(" ", normal));
        address.add(Chunk.NEWLINE);
        address.add(new Paragraph(" ", normal));
        Paragraph p11 = new Paragraph(value2, font);
        p11.setAlignment(Element.ALIGN_LEFT);
        p11.setPaddingTop(50);
        address.add(p11);
        address.add(new Paragraph(" ", normal));
        address.add(Chunk.NEWLINE);
        c2.setPhrase(address);
        c2.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(c2);

        PdfPCell c3 = new PdfPCell();
        c3.setFixedHeight(40);
        c3.setLeft(1f);
        c3.setMinimumHeight(25f);
        c3.setPaddingBottom(5f);
        Phrase addressPhrase = new Phrase();
        addressPhrase.add(new Paragraph(" ", normal));
        Paragraph p2 = new Paragraph(value3, font);
        p2.setAlignment(Element.ALIGN_LEFT);
        addressPhrase.add(p2);
        addressPhrase.add(Chunk.NEWLINE);
        addressPhrase.add(new Paragraph(" ", normal));
        addressPhrase.add(Chunk.NEWLINE);
        addressPhrase.add(new Paragraph(" ", normal));
        Paragraph p3 = new Paragraph(value4, font);
        p3.setAlignment(Element.ALIGN_LEFT);
        addressPhrase.add(p3);
        addressPhrase.add(new Paragraph(" ", normal));
        addressPhrase.add(Chunk.NEWLINE);
        c3.setPhrase(addressPhrase);
        c3.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(c3);
        document.add(table);
    }

    /**
     *  导出pdf 构建备注内容块
     * @param document
     * @param bfChinese
     * @param title
     * @param code
     * @param content
     * @throws Exception
     */
    public void getTableRemarkSpan(Document document,BaseFont bfChinese, String title, String code, String content) throws Exception {
        Font norma = new Font(bfChinese, 12, Font.BOLD, BaseColor.BLACK);
        Font normal = new Font(bfChinese, 8, Font.NORMAL, BaseColor.BLACK);
        PdfPTable bodytable = new PdfPTable(1);
        bodytable.setHorizontalAlignment(Element.ALIGN_CENTER);
        PdfPCell cell = new PdfPCell();
        cell.setBorderWidth(0.5f);
        cell.disableBorderSide(3);
        cell.setPaddingTop(0f);
        cell.setPaddingBottom(10f);
        Paragraph paragraph = new Paragraph(title, norma);
        paragraph.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(paragraph);
        bodytable.addCell(cell);

        if (!StringUtils.isEmpty(code)) {
            PdfPCell cell2 = new PdfPCell();
            cell2.setBorderWidth(0.5f);
            cell2.disableBorderSide(3);
            cell2.setPaddingTop(0f);
            cell2.setPaddingBottom(10f);
            Paragraph paragraph2 = new Paragraph("(" + code + ")", norma);
            paragraph2.setAlignment(Element.ALIGN_CENTER);
            cell2.addElement(paragraph2);
            bodytable.addCell(cell2);
        }

        PdfPCell cell3 = new PdfPCell();
        cell3.setBorderWidth(0.5f);
        cell3.disableBorderSide(3);
        cell3.setPaddingTop(0f);
        cell3.setPaddingBottom(10f);
        Paragraph paragraph3 = new Paragraph("  " + getTableNA(content), normal);
        paragraph3.setAlignment(Element.ALIGN_LEFT);
        cell3.addElement(paragraph3);
        bodytable.addCell(cell3);

        PdfPCell cell31 = new PdfPCell();
        cell31.setBorderWidth(0.5f);
        cell31.disableBorderSide(3);
        cell31.setPaddingTop(0f);
        cell31.setPaddingBottom(10f);
        // 出现换行次数
        int linCount = CharMatcher.is('\n').countIn(content);
        float questionContentHeight = content.length() > 100 ? content.length() / 3 : 10;
        float heigth = (360 - questionContentHeight) - (linCount * 10);
        cell31.setMinimumHeight(heigth);
        Paragraph paragraph31 = new Paragraph("    (以下无内容)", normal);
        paragraph31.setAlignment(Element.ALIGN_LEFT);
        cell31.addElement(paragraph31);
        bodytable.addCell(cell31);
        document.add(bodytable);
    }

    public void getTableIssuerInfoSpan(Document document,BaseFont bfChinese,String fileIds,String issueDate,String userName) throws Exception {
        Font normal1 = new Font(bfChinese, 9, Font.NORMAL, BaseColor.BLACK);
        PdfPTable bodytable1 = new PdfPTable(4);
        bodytable1.setWidths(new float[]{40f,20f,12f,20f});
        bodytable1.setWidthPercentage(80);
        String lastReviewPost = "中广核工程有限公司设备监造代表";
        PdfPCell pcell11 = new PdfPCell();
        pcell11.setFixedHeight(20);
        pcell11.disableBorderSide(11);
        pcell11.setBorderWidth(0.5f);
        Paragraph pParagraph11 = new Paragraph(" ", normal1);
        pParagraph11.setAlignment(Element.ALIGN_RIGHT);
        pcell11.addElement(pParagraph11);
        bodytable1.addCell(pcell11);

        PdfPCell pcell1 = new PdfPCell();
        pcell1.setFixedHeight(20);
        pcell1.disableBorderSide(15);
        pcell1.setBorderWidth(0.5f);
        Paragraph pParagraph1 = new Paragraph("签发人:", normal1);
        pParagraph1.setAlignment(Element.ALIGN_RIGHT);
        pcell1.addElement(pParagraph1);
        bodytable1.addCell(pcell1);

        PdfPCell pcell2 = new PdfPCell();
        pcell2.setFixedHeight(20);
        pcell2.disableBorderSide(15);
        pcell2.setBorderWidth(0.5f);
        Paragraph pParagraph2 = new Paragraph(userName, normal1);
        pParagraph2.setAlignment(Element.ALIGN_LEFT);
        pcell2.addElement(pParagraph2);
        bodytable1.addCell(pcell2);

        PdfPCell pcell3 = new PdfPCell();
        pcell3.setFixedHeight(20);
        pcell3.disableBorderSide(7);
        pcell3.setBorderWidth(0.5f);
        pcell3.setPaddingLeft(-20);
        pcell3.setHorizontalAlignment(Element.ALIGN_LEFT);
        pcell3.setVerticalAlignment(Element.ALIGN_LEFT);
        //根据id获取文件bytes
        if (!StringUtils.isEmpty(fileIds)) {
            ApiResult apiResult = upLoadApplication.fileDirectDownload(fileIds);
            if ("200".equals(apiResult.getCode())) {
                Map<String, String> data = (Map<String, String>) apiResult.getData();
                byte[] bytes = Base64.getDecoder().decode(data.get("fileBytes"));
                Image aurhorized = Image.getInstance(bytes);
                aurhorized.scaleAbsolute(60, 20);
                pcell3.setImage(aurhorized);
            }
        }
        bodytable1.addCell(pcell3);
        PdfPCell pcell12 = new PdfPCell();
        pcell12.setFixedHeight(20);
        pcell12.disableBorderSide(11);
        pcell12.setBorderWidth(0.5f);
        Paragraph pParagraph12 = new Paragraph(" ", normal1);
        pParagraph12.setAlignment(Element.ALIGN_RIGHT);
        pcell12.addElement(pParagraph12);
        bodytable1.addCell(pcell12);

        PdfPCell pcell4 = new PdfPCell();
        pcell12.setFixedHeight(20);
        pcell4.disableBorderSide(15);
        pcell4.setBorderWidth(0.5f);
        Paragraph pParagraph4 = new Paragraph("签发人职务:", normal1);
        pParagraph4.setAlignment(Element.ALIGN_RIGHT);
        pcell4.addElement(pParagraph4);
        bodytable1.addCell(pcell4);

        PdfPCell pcell44 = new PdfPCell();
        pcell12.setFixedHeight(20);
        pcell44.disableBorderSide(7);
        pcell44.setBorderWidth(0.5f);
        Paragraph pParagraph44 = new Paragraph(lastReviewPost, normal1);
        pParagraph44.setAlignment(Element.ALIGN_LEFT);
        pcell44.addElement(pParagraph44);
        pcell44.setColspan(2);
        bodytable1.addCell(pcell44);

        PdfPCell pcell444 = new PdfPCell();
        pcell444.disableBorderSide(9);
        pcell444.setBorderWidth(0.5f);
        pcell444.setPaddingBottom(8f);
        Paragraph pParagraph444 = new Paragraph(" ", normal1);
        pParagraph444.setAlignment(Element.ALIGN_LEFT);
        pcell444.addElement(pParagraph444);
        bodytable1.addCell(pcell444);

        PdfPCell pcell5 = new PdfPCell();
        pcell5.disableBorderSide(13);
        pcell5.setBorderWidth(0.5f);
        pcell5.setPaddingBottom(8f);
        Paragraph pParagraph5 = new Paragraph("签发日期:", normal1);
        pParagraph5.setAlignment(Element.ALIGN_RIGHT);
        pcell5.addElement(pParagraph5);
        bodytable1.addCell(pcell5);

        PdfPCell pcell55 = new PdfPCell();
        pcell55.setBorderWidth(0.5f);
        pcell55.disableBorderSide(5);
        pcell55.setPaddingBottom(8f);
        Paragraph pParagraph55 = new Paragraph(issueDate, normal1);
        pParagraph55.setAlignment(Element.ALIGN_LEFT);
        pcell55.addElement(pParagraph55);
        pcell55.setColspan(2);
        bodytable1.addCell(pcell55);
        document.add(bodytable1);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坏女人净画饼

原创辛苦

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值