ITEXT将HTML转为PDF内容被截断处理及相关问题总结

本文详细介绍了在使用iText将HTML转换为PDF时遇到的内容截断问题及其解决方案,包括单个循环内容和多个循环内容的处理策略,以及颜色显示异常的解决方法。此外,还总结了iText不识别的CSS样式,如flex、border-radius等,并提供了部分后端代码实现。
摘要由CSDN通过智能技术生成

ITEXT将HTML转为PDF内容被截断处理及相关问题总结

前言

记录一下使用itext将html文件转为pdf文件遇到的一些问题

一、ITEXT将HTML转为PDF内容被截断处理(一)

1.问题描述

直接上图:
在这里插入图片描述
表格,文字或者相关内容模块被自动分页截断

2.问题场景:

如上图中,整个大的模块,我称之为简历模块
简历模块的开始位置位于:pdf中间
简历模块内容:每一个模块高度固定,内容是动态循环生成

循环内容为独立循环,不是多个循环即只有一个循环体

3.解决

看图:
在这里插入图片描述

4.解决思路

简历开始页:
pdf整张高度为1000px
检测简历开始模块至本页结尾可以盛放的简历个数,比如个数为2

简历中间部分处理:
简历中间部分可以计算整张pdf页可以盛放简历的个数,比如3,
将简历开始页盛放的个数进行截取,并设置当前页单独为开始页,截取数为3,以此类推

简历结束页:
以每页3分简历自动撑开,其他以单独页处理。
可能会造成部分空白页

二、ITEXT将HTML转为PDF内容被截断处理(二)

1.问题描述

直接上图:
在这里插入图片描述

2.问题场景:

如上图中,整个大的模块,我称之为简历模块
简历模块的开始位置位于:新页的开始
简历模块内容:每一个模块高度固定,内容是动态循环生成

循环内容为多个循环体,如上同事同学同行三个循环体

3.解决

看图:
在这里插入图片描述
缺陷:可能会造成部分空白

4.解决思路

人脉圈开始页:
pdf整张高度为1000px
检测人脉圈开始模块至本页结尾可以盛放的同事同学同行的总个数,比如总个数为12

则可以做如下处理:当三个循环体总条数小于等于12时全部放置在一页,防止整页面空白出现的可能,其他情况则将三个循环体全部单独盛放为单独pdf页(如果想要更小几率出现空白页,则可以在此条件下做更进一步精细化条件判断)

人脉圈中间部分处理:
人脉圈中间部分可以计算整张pdf页可以盛放简历的个数,比如13(人脉圈首页开始的位置包含大标题),
将人脉圈开始页盛放的个数进行截取,并设置当前页单独为开始页,截取数为13,以此类推

人脉圈结束页:
以每页13分简历自动撑开,其他以单独页处理。
可能会造成部分空白页

三、常见问题

(1)常见问题及案例

总结的很全,解释也很到位
(2)常见问题补充
如果遇到在linux中生成的pdf与window中生成的pdf长度及宽度不一致问题,不要去找其他配置,尝试后效果不是很好,
建议直接这样调整:size一点点调试

@page {size:210mm 297mm;}

四、补充color问题

1.问题描述

直接上图:html页面中正常-转换完成后变这样
在这里插入图片描述
最后的“88”变成这样了,跟加了边框似的

2.解决

先看效果:
在这里插入图片描述

思路:
在这里插入图片描述
把样式中的font-weight去除即可

五、ITEXT转换为pdf时不识别的样式总结

flex, border-radius,圆角,阴影,rgba,overflow

六、贴一下后端部分代码实现

package com.gxj.test.service.impl;

import com.gxj.test.VO.ResultVO;
import com.gxj.test.pdfexport.PdfUtils;
import com.gxj.test.service.SellManager;
import com.gxj.test.utils.ResultVOUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class SellManagerImpl implements SellManager {

    @Override
    public ResultVO<String> sell() throws IOException {
        List<String> list = new ArrayList<>();
        list.add("小明");
        list.add("小明");
        list.add("小明");
        list.add("小明");
        list.add("小明");
        ResultVO success = ResultVOUtil.success(list);

        return success;
    }

    @Override
    public void pdfReport() throws Exception {
        //生成pdf
        StringBuilder htmlStr = new StringBuilder();
        htmlStr.append("<html>");
        htmlStr.append("<head>");
        htmlStr.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");

        htmlStr.append("<style mce_bogus=\"1\" type=\"text/css\">");
        htmlStr.append("*{margin:0;padding:0;border:none}body{background-color:#fff}.main{margin:0 auto;width:100%;height:100%;background-color:#fff}.pp{position:relative;box-sizing:border-box;width:100%}.p1{height:100%;min-height:970px}.p2{padding:0}.p21{position:relative;overflow:hidden;width:100%;height:auto}p.tit{position:absolute;top:15%;width:100%;text-align:center;letter-spacing:1px;font-weight:800;font-size:36px}p.tit_1{position:absolute;top:22%;width:100%;text-align:center;letter-spacing:1px;font-weight:800;font-size:33px}p.tit_f{position:absolute;top:29%;width:100%;text-align:center;letter-spacing:1px;font-size:16px}p.time{position:absolute;top:78%;width:100%;text-align:center;font-weight:800;font-size:18px}p.dad{position:absolute;top:85%;width:100%;text-align:center;font-weight:800;font-size:18px}.title{position:absolute;top:20px;left:0;box-sizing:border-box;width:100%;height:40px;border-bottom:1px solid #666}.title_l{float:left;padding-left:12px;width:300px;height:40px;font-size:12px;line-height:47px}.title_r{float:right;padding-left:52px;width:244px;height:40px;font-size:12px;line-height:47px}.statement{position:absolute;top:114px;left:0;width:100%;height:172px;text-align:left}.title_s{overflow:hidden;margin-bottom:10px;top:0px;text-align:center;word-wrap:break-word;font-weight:800;font-size:18px;word-break:break-all}.title_ff{overflow:hidden;margin-bottom:5px;text-indent:2em;word-wrap:break-word;font-size:14px;word-break:break-all}.statement_main{position:relative;left:0;overflow:hidden;width:100%;height:auto;text-align:left}.ttt{margin-bottom:7px;width:100%;height:auto;min-height:36px;background:#005aaa;color:#fff;text-align:center;font-weight:500;font-size:14px;line-height:36px}.group{margin-bottom:7px;width:100%;height:30px;background:#fff;line-height:30px}.l2_l{float:left;margin-right:1px;width:39%;font-size:14px}.l2_r{float:right;width:60%;height:30px;font-size:13px;line-height:30px}.c1{height:22px;background:#e8f5fb;line-height:22px}.c0{height:22px;background:#005aaa;color:#fff;text-align:center;line-height:22px}.c2{height:22px;background:#f5f5f5;line-height:22px}.c3{height:22px;background:#999;color:#fff;line-height:22px}.statement_group{overflow:hidden;margin-bottom:15px;padding-bottom:6px;width:100%;height:auto}.l3_l{float:left;margin-right:.5%;width:10%;height:30px}.l3_c{float:left;margin-right:.5%;width:40%;height:30px}.l3_r{float:left;width:49%;height:30px}.l3_s{color:#fff;font-size:13px;line-height:30px}.l3_s2{color:#000;font-size:13px;line-height:30px}.w163{float:left;margin-right:.5%;width:24%;height:30px}.w178{float:left;margin-right:.5%;width:26%;height:30px}.w50{float:left;width:49%;height:30px;line-height:30px}.w25{float:left;width:25%;height:30px;line-height:30px}.ttt2{margin-bottom:7px;width:100%;min-height:36px;background:#005aaa;background-color:#999;color:#fff;text-align:left;font-weight:500;font-size:14px;line-height:36px}.pr4{box-sizing:border-box;margin-right:.5%}.mb15{margin-bottom:15px}.table>tbody>tr>td,.table>tbody>tr>th,.table>tfoot>tr>td,.table>tfoot>tr>th,.table>thead>tr>td,.table>thead>tr>th{padding:8px;height:22px;border-top:none;vertical-align:top;line-height:22px}.table td{border-right:4px solid #fff;border-bottom:5px solid #fff;font-size:14px}.table td:last-child{border-right:none}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}table{width:100%;background-color:transparent}");
        htmlStr.append("@page {" +
                "@top-center {content: element(header)}" +
                "@bottom-center {content: element(footer)}" +
                "}" +
                ".header1 {position: running(header);}" +
                ".footer { position: running(footer) }");
        htmlStr.append("#pagenumber:before {content: counter(page); }");  //页码
        htmlStr.append("@page{}.pageNext{page-break-after: always;} ");
        htmlStr.append("div.footer-left {display: block;position: running(footer-left);}");
        htmlStr.append("div.footer-right {display: block;position: running(footer-right); }");
        htmlStr.append("div.header-left {display: block;position: running(header-left);}");
        htmlStr.append("div.header-right {display: block;position: running(header-right); }");
        htmlStr.append("table { page-break-inside:auto; -fs-table-paginate:paginate;border-spacing: 0;border: 1px; table-layout:fixed}");
        htmlStr.append(" tr    { page-break-inside:avoid; page-break-after:auto;}");
        htmlStr.append(" td,th { line-height:25px;word-wrap:break-word;word-break:break-all; padding-left:5px; padding-right:5px;}");
        htmlStr.append(" .wordBreak    { float:left;word-wrap: break-word;word-break: break-all;white-space: pre-wrap !important;}");
        htmlStr.append(" thead { display:table-header-group;margin-top: 100px;padding-top: 100px; }");
        htmlStr.append("  tfoot { display:table-footer-group; }");
        htmlStr.append("  </style> ");
        htmlStr.append("</head>");
        htmlStr.append("<body style=\"margin:0;padding:0 30px;font-family:'Microsoft YaHei UI',STXingkai\">");

        //第一页
        htmlStr.append("<div style=\"width: 100%;background-color: #fff;display: flex;flex-direction: column;align-items: center;padding-top: 109px;box-sizing: border-box;\">");
        htmlStr.append("<img src=\"file:\\D:\\reprotPDF\\img\\logo.png\" style=\"display:block;width: 200px;height: auto;margin: 0 auto;\" />");
        htmlStr.append("<div style=\"width: 200px;height: 60px;margin: 0 auto;\"></div>");
        htmlStr.append("<img src=\"file:\\D:\\reprotPDF\\img\\page1title.png\" style=\"display:block;width: 600px;height: auto;margin: 0 auto;\" />");
        htmlStr.append("<div style=\"width: 832px;height: 177px;margin-top: 260px;\">");
        htmlStr.append("<div style=\"float: left;margin-right: 36px;margin-top:30px;height: 177px;display: flex;flex-direction: column;justify-content: space-around;align-items: flex-start;font-size: 18px;color: #000;\">");
        htmlStr.append("<div>杭州轩宇人力资源有限公司</div>");
        htmlStr.append("<div>地址:浙江省杭州市滨江区江陵路1760号</div>");
        htmlStr.append("<div>邮编:310051</div>");
        htmlStr.append("<div>电话:0571-28098487</div>");
        htmlStr.append("<div>邮箱:yunchao.zhou@91zhizhen.com </div>");
        htmlStr.append("<div>网址:www.91zhizhen.com</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"float: left;\">");
        htmlStr.append("<img src=\"file:\\D:\\reprotPDF\\img\\page1bot.png\" style=\"width: 270px;height: 78px;margin-right: 50px;\" />");
        htmlStr.append("<div style=\"display: flex;flex-direction: row;justify-content: flex-end;\">");
        htmlStr.append("<img src=\"file:\\D:\\reprotPDF\\img\\erwei.jpg\" style=\"width: 90px;height: 90px;margin-right: 40px;\" />");
        htmlStr.append("<img src=\"file:\\D:\\reprotPDF\\img\\erwei.jpg\" style=\"width: 90px;height: 90px;\" />");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");

        //第二页pdf-width~600px
        htmlStr.append("<div style=\"width: 100%;height: auto;background-color: #fff;box-sizing: border-box;position: relative;\">");
        htmlStr.append("<div style=\"float:left;font-size: 14px;color: #999;padding-top:10px;margin-right:160px;\">");
        htmlStr.append("<div>报告编号:ZHIZHEN-2021010300200085</div>");
        String sameDate = DateFormatUtils.format(new Date(), "yyyy 年 MM 月 dd 日 HH:mm:ss");
        htmlStr.append("<div>本报告生成时间为" ).append(sameDate).append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<img style=\"float:left;width: 160px;height: 56px;\" src=\"file:\\D:\\reprotPDF\\img\\logoheader.png\" />");
        htmlStr.append("<div style=\"width: 600px;height: 755px;margin: 88px auto 0;;position: relative;\">");
        htmlStr.append("<img src=\"file:\\D:\\reprotPDF\\img\\page2back.png\" style=\"width: 560px;height: 560px;position: absolute;top: 90px;left: 10px;\" />");
        htmlStr.append("<img src=\"file:\\D:\\reprotPDF\\img\\page1title.png\" style=\"width: 600px;height: auto;position: absolute;top: 260px;left: 10px;\" />");
        htmlStr.append("<div style=\"font-size: 66px;height: 80px;line-height: 80px;text-align: center;color: #000;position: absolute;top: 360px;width: 100%;\">");
        htmlStr.append("迪迦");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"position: absolute;top: 466px;left:0;width: 100%;\">");
        htmlStr.append("<div style=\"width: 220px;height: 50px;border: 1px solid #169171;border-radius: 26px;text-align:center;line-height:50px;font-size: 26px;color: #000;margin:0 auto;\">指真标准版</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;font-size: 16px;color: #666;margin: 0 auto;margin-top: 60px;\">");
        htmlStr.append("<div style=\"margin-bottom:4px;\">报告内容声明:</div>");
        htmlStr.append("<div style=\"margin-bottom:4px;\">指真网通过合法途径获得本报告内容。报告中的公开点评信息(包括人脉圈、人脉点评、印象</div>");
        htmlStr.append("<div style=\"margin-bottom:4px;\">标签、推荐信、好友点评详情等)仅代表点评人个人观点,不代表指真网观点,因该点评引发</div>");
        htmlStr.append("<div style=\"margin-bottom:4px;\">的任何争议与指真网无关。本报告应仅为您的决策提供参考,因使用该报告而产生的任何后果</div>");
        htmlStr.append("<div style=\"margin-bottom:4px;\">指真网概不负责。</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");

        //第三页
        htmlStr.append("<div style=\"width: 100%;height: auto;background-color: #fff;padding-top: 260px;box-sizing: border-box;position: relative;\">");
        htmlStr.append("<img src=\"file:\\D:\\reprotPDF\\img\\logoheader.png\" style=\"width: 164px;height: 60px;position: absolute;top: 60px;left: 466px;\" />");
        htmlStr.append("<div style=\"font-size: 80px;color: #169171;margin-left:32px;\">目录</div>");
        htmlStr.append("<div style=\"font-size: 30px;font-weight: 400;color: #000000;margin-left: 30px;margin-top: 90px;line-height: 56px;\">");
        htmlStr.append("<div>1.报告概述</div>");
        htmlStr.append("<div>2.基本信息</div>");
        htmlStr.append("<div>3.教育信息</div>");
        htmlStr.append("<div>4.工作信息</div>");
        htmlStr.append("<div>5.人脉圈</div>");
        htmlStr.append("<div>6.人脉点评</div>");
        htmlStr.append("<div>7.印象标签</div>");
        htmlStr.append("<div>8.推荐信</div>");
        htmlStr.append("<div>9.好友点评详情</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");

        //第四页
        htmlStr.append("<div style=\"width: 100%;height: auto;background-color: #fff;padding: 188px 0px 0 0;box-sizing: border-box;position: relative;\">");
        htmlStr.append("<img src=\"file:\\D:\\reprotPDF\\img\\logoheader.png\" style=\"width: 164px;height: 60px;position: absolute;top: 120px;left: 466px;\" />");
        htmlStr.append("<div style=\"font-size: 36px;font-weight: 400;color: #169171;line-height: 65px;\">一、报告概述</div>");
        htmlStr.append("<div style=\"box-sizing: border-box;width: 100%;padding-left: 50px;padding-top: 16px;\">");
        htmlStr.append("<div style=\"font-size: 28px;color: #000000;font-weight: 500;margin-bottom: 14px;\">迪迦</div>");
        htmlStr.append("<div style=\"font-size: 14px;color: #000000;line-height: 20px;\">国籍:   中国 </div>");
        htmlStr.append("<div style=\"font-size: 14px;color: #000000;line-height: 20px;\">性别:   男</div>");
        htmlStr.append("<div style=\"font-size: 14px;color: #000000;line-height: 20px;\">出生日期:   1980.08.08</div>");
        htmlStr.append("<div style=\"width: 95%;height: 158px;background: #FFFFFF;border: 1px solid #D2D2D2;box-sizing: border-box;margin-top: 30px;\">");
        htmlStr.append("<div style=\"width: 100%;height: 36px;box-sizing: border-box;border-bottom: 4px solid #169171;background-color: #deefe9;display: block;color: #169171;\">");
        htmlStr.append("<div style=\"width: 20%;font-weight: bold;display: inline-block;height: 36px;font-size: 14px;line-height: 36px;color: #169171;box-sizing: border-box;padding-left: 23px;border-right: 1px solid #D2D2D2;float:left;\">");
        htmlStr.append("项目信息");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 60%;font-weight: bold;display: inline-block;height: 36px;font-size: 14px;line-height: 36px;color: #169171;box-sizing: border-box;padding-left: 33px;float:left;\">");
        htmlStr.append("项目内容");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 100px;box-sizing: border-box;display: block;\">");
        htmlStr.append("<div style=\"width: 20%;display: inline-block;float:left;height: 98px;font-size: 14px;line-height: 30px;color: #000;box-sizing: border-box;padding-left: 23px;border-right: 1px solid #D2D2D2;line-height: 38px;padding-bottom: 20px;\">");
        htmlStr.append("<div>教育信息</div>");
        htmlStr.append("<div>工作信息</div>");
        htmlStr.append("<div>印象标签</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 60%;display: inline-block;float:left;height: 100px;font-size: 14px;line-height: 30px;color: #000;box-sizing: border-box;padding-left: 33px;line-height: 38px;padding-bottom: 20px;\">");
        htmlStr.append("<div>2段教育信息</div>");
        htmlStr.append("<div>3段工作信息</div>");
        htmlStr.append("<div>印象标签数77;最多标签名(勤奋踏实25,积极主动36 )</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 240px;box-sizing: border-box;display: flex;justify-content: space-between;align-items: center;flex-direction: row;margin-top: 40px;\">");
        htmlStr.append("<div style=\"width: 20%;height: 160px;border: 1px solid #D2D2D2;border-radius: 10px;box-sizing: border-box;padding: 20px 30px;display: inline-block;margin-right:20px;'\">");
        htmlStr.append("<div style=\"font-size: 16px;text-align: center;\">人脉</div>");
        htmlStr.append("<div style=\"width: 100%;font-weight: bold;text-align: center;color: #169171;font-size: 28px;height: 50px;width: 100%;box-sizing: border-box;padding-top: 5px;display: flex;align-items: center;justify-content: center;border-bottom: 1px dashed #D2D2D2;\">121</div>");
        htmlStr.append("<div style=\"margin-left: 6px;font-size: 16px;color: #888888;line-height: 30px;font-weight: 400;margin-top: 10px;\">同事 35</div>");
        htmlStr.append("<div style=\"margin-left: 6px;font-size: 16px;color: #888888;line-height: 30px;font-weight: 400;\">同学 45</div>");
        htmlStr.append("<div style=\"margin-left: 6px;font-size: 16px;color: #888888;line-height: 30px;font-weight: 400;\">同行 31</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 20%;height: 160px;border: 1px solid #D2D2D2;border-radius: 10px;box-sizing: border-box;padding: 20px 30px;display: inline-block;margin-right:20px;\">");
        htmlStr.append("<div style=\"font-size: 16px;text-align: center;\">人脉点评</div>");
        htmlStr.append("<div style=\"width: 100%;font-weight: bold;text-align: center;color: #169171;font-size: 28px;height: 50px;width: 100%;box-sizing: border-box;padding-top: 5px;display: flex;align-items: center;justify-content: center;border-bottom: 1px dashed #D2D2D2;\">121</div>");
        htmlStr.append("<div style=\"margin-left: 6px;font-size: 16px;color: #888888;line-height: 30px;font-weight: 400;margin-top: 10px;\">同事 35</div>");
        htmlStr.append("<div style=\"margin-left: 6px;font-size: 16px;color: #888888;line-height: 30px;font-weight: 400;\">同学 45</div>");
        htmlStr.append("<div style=\"margin-left: 6px;font-size: 16px;color: #888888;line-height: 30px;font-weight: 400;\">同行 31</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 20%;height: 160px;border: 1px solid #D2D2D2;border-radius: 10px;box-sizing: border-box;padding: 20px 30px;display: inline-block;\">");
        htmlStr.append("<div style=\"font-size: 16px;text-align: center;\">推荐信</div>");
        htmlStr.append("<div style=\"width: 100%;font-weight: bold;text-align: center;color: #169171;font-size: 28px;height: 50px;width: 100%;box-sizing: border-box;padding-top: 5px;display: flex;align-items: center;justify-content: center;border-bottom: 1px dashed #D2D2D2;\">121</div>");
        htmlStr.append("<div style=\"margin-left: 6px;font-size: 16px;color: #888888;line-height: 30px;font-weight: 400;margin-top: 10px;\">同事 35</div>");
        htmlStr.append("<div style=\"margin-left: 6px;font-size: 16px;color: #888888;line-height: 30px;font-weight: 400;\">同学 45</div>");
        htmlStr.append("<div style=\"margin-left: 6px;font-size: 16px;color: #888888;line-height: 30px;font-weight: 400;\">同行 31</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 70%;height: 180px;border: 1px solid #D2D2D2;border-radius: 10px;margin-top: 0;display: inline-block;\">");
        htmlStr.append("<div style=\"width: 100%;height: 58px;font-size: 16px;color: #000000;font-weight: 400;text-align: center;line-height: 58px;\">");
        htmlStr.append("印象评分");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 180px;display: flex;align-items: center;justify-content: space-between;\">");
        htmlStr.append("<div style=\"width: 50%;height: 80px;box-sizing: border-box;border-right: 1px dashed #D2D2D2;display: inline-block;float:left;\">");
        htmlStr.append("<div style=\"font-size: 28px;font-weight: bold;color: #169171;line-height: 28px;text-align: center;\">");
        htmlStr.append("88");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"font-size: 16px;font-weight: 400;color: #888888;line-height: 44px;text-align: center;\">");
        htmlStr.append("同事评分");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"font-size: 16px;font-weight: 400;color: #888888;line-height: 24px;text-align: center;\">");
        htmlStr.append("排名12,超过98%的人才");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 48%;height: 120px;box-sizing: border-box;display: inline-block;float:left;\">");
        htmlStr.append("<div style=\"font-size: 28px;font-weight: bold;color: #169171;line-height: 28px;text-align: center;\">");
        htmlStr.append("88");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"font-size: 16px;font-weight: 400;color: #888888;line-height: 44px;text-align: center;\">");
        htmlStr.append("同学评分");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"font-size: 16px;font-weight: 400;color: #888888;line-height: 24px;text-align: center;\">");
        htmlStr.append("排名12,超过98%的人才");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");

//        第五页
        htmlStr.append("<div style=\"width: 100%;height: 100%;background-color: #fff;padding: 0;box-sizing: border-box;position: relative;\">");
        htmlStr.append("<img src=\"file:\\D:\\reprotPDF\\img\\logoheader.png\" style=\"width: 164px;height: 60px;position: absolute;top: 0px;left: 466px;\" />");
        htmlStr.append("<div style=\"font-size: 48px;font-weight: 400;color: #169171;line-height: 65px;\">二、基本信息</div>");
        htmlStr.append("<div style=\"box-sizing: border-box;width: 100%;padding-left: 50px;padding-top: 30px;\">");
        htmlStr.append("<div style=\"width: 90%;height: 400F;border: 1px solid #D2D2D2;box-sizing: border-box;\">");
        htmlStr.append("<div style=\"width: 100%;height: 50px;box-sizing: border-box;border-bottom: 4px solid #169171;background-color: #deefe9;display: flex;flex-direction: row;\">");
        htmlStr.append("<div style=\"width:30%;height: 46px;display: inline-block;float:left;\"></div>");
        htmlStr.append("<div style=\"width:60%;display: inline-block;float:left;height: 46px;line-height: 46px;align-items: center;font-size: 20px;color: #169171;box-sizing: border-box;padding-left: 33px;\">");
        htmlStr.append("基本信息");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 280px;box-sizing: border-box;display: flex;flex-direction: row;\">");
        htmlStr.append("<div style=\"width: 30%;display: inline-block;float:left;height: 280px;justify-content: center;font-size: 16px;color: #000;box-sizing: border-box;padding-left: 23px;border-right: 1px solid #D2D2D2;flex-direction: column;line-height: 40px;\">");
        htmlStr.append("<div>姓名</div>");
        htmlStr.append("<div>性别</div>");
        htmlStr.append("<div>生日</div>");
        htmlStr.append("<div>地区</div>");
        htmlStr.append("<div>手机</div>");
        htmlStr.append("<div>邮箱</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 60%;display: inline-block;float:left;height: 280px;justify-content: center;font-size: 16px;color: #000;box-sizing: border-box;padding-left: 33px;flex-direction: column;line-height: 40px;\">");
        htmlStr.append("<div>").append(1).append("</div>");
        htmlStr.append("<div>").append(1).append("</div>");
        htmlStr.append("<div>").append(1).append("</div>");
        htmlStr.append("<div>").append(1).append("</div>");
        htmlStr.append("<div>").append(1).append("</div>");
        htmlStr.append("<div>").append(1).append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");

        //教育信息
        htmlStr.append("<div style=\"font-size: 48px;font-weight: 400;color: #169171;line-height: 65px;margin-top: 40px;\">三.教育信息</div>");
        htmlStr.append("<div style=\"display: flex;flex-wrap:wrap;width: 900px;\">");
        htmlStr.append("<div style=\"width: 40%;height: auto;margin-right: 46px;box-sizing: border-box;padding-left: 50px;display: inline-block;float:left;margin-right:20px;\">");
        htmlStr.append("<div style=\"font-size: 24px;line-height: 32px;color: #333333;font-weight: 400;margin: 42px 0 24px;\">");
        htmlStr.append("第").append(1).append("份学历信息</div>");
        htmlStr.append("<div style=\"width: 100%;height: 300px;background: #FFFFFF;border: 2px solid #eeeeee;border-radius: 10px;box-sizing: border-box;padding: 14px 28px 0;\">");
        htmlStr.append("<div style=\"font-size: 24px;font-weight: 400;color: #169171;line-height: 54px;\">");
        htmlStr.append(1).append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 36px;\">");
        htmlStr.append("<div style=\"width: 86px;font-size: 16px;color: #999;display: inline-block;float:left;line-height: 36px;\">学校名称</div>");
        htmlStr.append("<div style=\"font-size: 16px;color: #333;display: inline-block;float:left;line-height: 36px;\">").append(1).append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 36px;display: flex;flex-direction: row;align-items: center;\">");
//            htmlStr.append("<div style=\"width: 86px;font-size: 16px;color: #999;display: inline-block;float:left;line-height: 36px;\">所在国家</div>");
//            htmlStr.append("<div style=\"font-size: 16px;color: #333;display: inline-block;float:left;line-height: 36px;\">英国</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 36px;display: flex;flex-direction: row;align-items: center;\">");
        htmlStr.append("<div style=\"width: 86px;font-size: 16px;color: #999;display: inline-block;float:left;line-height: 36px;\">学习时间</div>");
        htmlStr.append("<div style=\"font-size: 16px;color: #333;display: inline-block;float:left;line-height: 36px;\">").append(1).append("-").append(1).append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 36px;display: flex;flex-direction: row;align-items: center;\">");
        htmlStr.append("<div style=\"width: 86px;font-size: 16px;color: #999;display: inline-block;float:left;line-height: 36px;\">专业</div>");
        htmlStr.append("<div style=\"font-size: 16px;color: #333;display: inline-block;float:left;line-height: 36px;\">").append(1).append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 36px;display: flex;flex-direction: row;align-items: center;\">");
        htmlStr.append("<div style=\"width: 86px;font-size: 16px;color: #999;display: inline-block;float:left;line-height: 36px;\">学历层次</div>");
        htmlStr.append("<div style=\"font-size: 16px;color: #333;display: inline-block;float:left;line-height: 36px;\">").append(1).append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 36px;display: flex;flex-direction: row;align-items: center;\">");
//            htmlStr.append("<div style=\"width: 86px;font-size: 16px;color: #999;display: inline-block;float:left;line-height: 36px;\">学习形式</div>");
//            htmlStr.append("<div style=\"font-size: 16px;color: #333;display: inline-block;float:left;line-height: 36px;\">普通全日制</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");

        //工作信息
        htmlStr.append("<div style=\"font-size: 48px;font-weight: 400;color: #169171;line-height: 65px;margin-top: 80px;margin-bottom: 10px;\">四.工作信息</div>");
        htmlStr.append("<div style=\"box-sizing: border-box;padding-left: 48px;\">");
        htmlStr.append("<div style=\"font-size: 24px;font-weight: 400;color: #333333;line-height: 64px;\">");
        htmlStr.append("第一份履历:杭州轩宇人力资源有限公司");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 90%;height: 270px;background: #FFFFFF;border: 2px solid #eeeeee;border-radius: 10px;box-sizing: border-box;padding:0 26px;\">");
        htmlStr.append("<div style=\"font-size: 24px;font-weight: 400;color: #169171;line-height: 72px;padding-left: 8px;\">");
        htmlStr.append("杭州轩宇人力资源有限公司");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 42px;box-sizing: border-box;line-height: 42px;border-bottom: 1px solid #EAEAEA;display: flex;flex-direction: row;align-items: center;padding-left: 4px;\">");
        htmlStr.append("<div style=\"width: 96px;color: #999999;font-size: 16px;display: inline-block;float:left;\">");
        htmlStr.append("公 司");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 400px;color: #333333;font-size: 16px;display: inline-block;float:left;\">");
        htmlStr.append("杭州轩宇人力资源有限公司");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 42px;box-sizing: border-box;line-height: 42px;border-bottom: 1px solid #EAEAEA;display: flex;flex-direction: row;align-items: center;padding-left: 4px;\">");
        htmlStr.append("<div style=\"width: 96px;color: #999999;font-size: 16px;display: inline-block;float:left;\">");
        htmlStr.append("地 区");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 400px;color: #333333;font-size: 16px;display: inline-block;float:left;\">");
        htmlStr.append("杭州轩宇人力资源有限公司");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 42px;box-sizing: border-box;border-bottom: 1px solid #EAEAEA;display: flex;flex-direction: row;align-items: center;padding-left: 4px;\">");
        htmlStr.append("<div style=\"width: 50%;display: flex;flex-direction: row;align-items: center;display: inline-block;float:left;\">");
        htmlStr.append("<div style=\"width: 96px;color: #999999;font-size: 16px;display: inline-block;float:left;line-height: 42px;\">");
        htmlStr.append("部 门");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100px;color: #333333;font-size: 16px;display: inline-block;float:left;line-height: 42px;\">");
        htmlStr.append("技术部");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 48%;display: flex;flex-direction: row;align-items: center;display: inline-block;float:left;\">");
        htmlStr.append("<div style=\"width: 96px;color: #999999;font-size: 16px;box-sizing: border-box;padding-right: 30px;text-align: right;display: inline-block;float:left;line-height: 42px;\">");
        htmlStr.append("职 位");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100px;color: #333333;font-size: 16px;display: inline-block;float:left;line-height: 42px;\">");
        htmlStr.append("产品经理");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100%;height: 42px;box-sizing: border-box;border-bottom: 1px solid #EAEAEA;display: flex;flex-direction: row;align-items: center;padding-left: 4px;\">");
        htmlStr.append("<div style=\"width: 50%;display: flex;flex-direction: row;align-items: center;display: inline-block;float:left;\">");
        htmlStr.append("<div style=\"width: 96px;color: #999999;font-size: 16px;display: inline-block;float:left;line-height: 42px;\">");
        htmlStr.append("入职时间");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100px;color: #333333;font-size: 16px;display: inline-block;float:left;line-height: 42px;\">");
        htmlStr.append("2020.12.20");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 48%;display: flex;flex-direction: row;align-items: center;display: inline-block;float:left;\">");
        htmlStr.append("<div style=\"width: 96px;color: #999999;font-size: 16px;box-sizing: border-box;padding-right: 30px;text-align: right;display: inline-block;float:left;line-height: 42px;\">");
        htmlStr.append("离职时间");
        htmlStr.append("</div>");
        htmlStr.append("<div style=\"width: 100px;color: #333333;font-size: 16px;display: inline-block;float:left;line-height: 42px;\">");
        htmlStr.append("2020.12.1");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</div>");
        htmlStr.append("</body>");
        htmlStr.append("</html>");
        String pdfPath = "D:\\reprotPDF\\1.pdf";
        System.out.println("1111");
        PdfUtils.generateToFile(htmlStr.toString(), pdfPath);
    }
}

七、关于前端实现pdf

jspdf + html2canvas 实现html转pdf
实现一
实现二

总结:jspdf在手机端支持很差。除了谷歌浏览器可以,火狐浏览器偶尔可以以外,安卓自带浏览器以及safari都都存在问题。

总结

以上是ITEXT转HTML为PDF遇到问题的总结

后端生成的pdf:1.在样式显示上完全没有异常;2.生成的pdf大多几十kb(前端生成大多大几百kb);3.完全没有兼容性问题。

根据引用,你提到了使用iTextHTML文件转为PDF文件时遇到了一些问题。引用提到后端生成的PDF没有样式异常,且文件大小较小。然后引用提到了关于ITEXTHTML转为PDF内容截断处理的解决方法。 根据引用中的内容,你可能遇到了循环内容截断问题。如果循环内容是独立的,只有一个循环体,并且内容截断,可以按照以下解决思路来解决:将循环体的总条数判断是否小于等于12,如果是则将所有内容放在一页上,以防止空白页的出现;如果不是,则将每个循环体都放在单独的PDF页上。这样可以避免内容截断问题。 如果循环内容是多个循环体,并且内容截断,可以按照引用中的解决思路来解决:判断三个循环体的总条数是否小于等于12,如果是,则将所有内容放在一页上,以防止空白页的出现;如果不是,则将每个循环体都放在单独的PDF页上。 综上所述,你提到的iText图片转PDF截断问题可以通过以上的解决思路来解决。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [ITEXTHTML转为PDF内容截断处理相关问题总结](https://blog.csdn.net/weixin_45439379/article/details/116539569)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值