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

文章目录

  • ITEXT将HTML转为PDF内容被截断处理及相关问题总结
  • 前言
  • 一、ITEXT将HTML转为PDF内容被截断处理(一)
    • 1.问题描述
    • 2.问题场景:
      • 循环内容为独立循环,不是多个循环即只有一个循环体
    • 3.解决
    • 4.解决思路
  • 二、ITEXT将HTML转为PDF内容被截断处理(二)
    • 1.问题描述
    • 2.问题场景:
      • 循环内容为多个循环体,如上同事同学同行三个循环体
    • 3.解决
    • 4.解决思路
      • 则可以做如下处理:当三个循环体总条数小于等于12时全部放置在一页,防止整页面空白出现的可能,其他情况则将三个循环体全部单独盛放为单独pdf页(如果想要更小几率出现空白页,则可以在此条件下做更进一步精细化条件判断)
  • 三、常见问题
  • 四、补充color问题
    • 1.问题描述
    • 2.解决
  • 五、ITEXT转换为pdf时不识别的样式总结
  • 六、贴一下后端部分代码实现
  • 七、关于前端实现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 {@Overridepublic 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;}@Overridepublic void pdfReport() throws Exception {//生成pdfStringBuilder 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~600pxhtmlStr.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.完全没有兼容性问题。

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

  1. html页面导出pdf截断问题,html2canvas 与 jspdf 相结合生成 pdf 内容被截断的终极解决方案...

    欢迎关注我的公众号 <人生代码> 我有一个大胆的想法,我要一直写到死,那一天我不写了,可能就死了.哈哈. 哈喽,大家好,我是你们的攻城狮,人贱人爱的 Ken,一个永远充满激情的人. 最近接 ...

  2. itext将html转为pdf,图片标签为base64的处理

    2019独角兽企业重金招聘Python工程师标准>>> 在http://my.oschina.net/yifanxiang/blog/678139中.修改了一下代码如下: /*** ...

  3. itext实现pdf内容替换

    源码 源码:https://github.com/lastwhispers/pdf-content-replace 能干什么 基于java语言itext库,实现pdf内容替换. 比如将银行电子回执单P ...

  4. Itext旋转PDF内容的方法

    前不久使用Freemarker+Flying sauser +Itext 整合生成PDF,因打印要求,需要旋转PDF里的内容,使用过Pdf-renderer, PDFBox 和JPedal转PDF为图 ...

  5. iText框架(生成pdf文档)

    1.创建一个itext的简单示例 a.导包(pom.xml文件) <dependencies><dependency><groupId>com.lowagie< ...

  6. java使用poi、itextpdf将word、ppt转为pdf文件,并对pdf文件加盖签章

    1 环境及背景 SpringBoot项目,使用poi.itextpdf将excel.ppt.word文件转为pdf,并对pdf文件进行签章: 对Excel文件加图片水印,并加密设置为只读. 下面的方法 ...

  7. JAVA itext 多种文件转pdf,进行合并 添加水印

    结合网上各路大神代码汇总而来,如果需要将pdf统一格式,可将pdf转成图片后重新转为pdf合并至一起,使用itext的PdfCanvas未成功解决该问题,主要也是因为我菜且时间紧没空查文档了.对于it ...

  8. java网页保存pdf_JavaScript+Java实现HTML页面转为PDF文件保存的方法

    JavaScript+Java实现HTML页面转为PDF文件保存的方法 发布于 2017-02-27 09:58:50 | 160 次阅读 | 评论: 0 | 来源: 网友投递 JavaScript客 ...

  9. IText实现url转pdf, 解决中文字体问题

    IText实现url转pdf 入门文章:http://www.micmiu.com/opensource/expdoc/itext-pdf-demo/ 进阶文章:http://www.micmiu.c ...

最新文章

  1. UA MATH567 高维统计IV Lipschitz组合8 随机投影与John-Lindenstrauss引理
  2. 一种绕开反病毒引擎的方法
  3. SQL Server 2000+ADO.NET实现并发控制
  4. 计算机考试考前准备,考前必看如何正确准备计算机等级考试 -电脑资料
  5. JVM--对象的实例化过程
  6. Android之Color颜色值和RGB颜色对照表
  7. 码云上传代码添加标签_第一次使用Git Bash Here 将本地代码上传到码云
  8. randn函数加噪声_语义分割中常用的损失函数1(基础篇)
  9. python字符串变量s的值是python网络爬虫_【Python爬虫作业】-字符串
  10. gogs可以自动化部署吗_效率提升利器:你还害怕自动化部署吗?
  11. 倍增LCA(bzoj 3732: Network)
  12. 【Silverlight】Bing Maps学习系列(二):通过Bing Maps Silverlight Control如何显示地图...
  13. SpringBoot2.0之整合Dubbo
  14. SQLite数据库学习小结——Frameworks层实现
  15. ISCC2021-WP合集
  16. max的标准库头文件 c语言,float.h - C语言标准库
  17. 商业研究(5):宠物服务市场-概览
  18. 算法--二分查找(python实现)
  19. 【小y设计】二维码条形码打印编辑器
  20. 拆字在线版-扌斥字在纟戋片反【转】------字库增强版

热门文章

  1. Linux-动态监控进程
  2. 20k+招聘要求(截图自boss直聘)
  3. 数字藏品平台开发|通过我们的 NFT 音乐市场开发服务发现您独特的音乐
  4. 桌面文件太多?这个神器一键整理只需三秒!
  5. Java策略模式(Strategy)
  6. beego原生mysql查询_go——beego的数据库增删改查
  7. RDB内存快照:Redis如何实现快速恢复数据
  8. Xtreme9.0 - Light Gremlins 容斥
  9. 计算机软件科学家谢涛,计算机软件科学家谢涛:星辰大海,求思进取
  10. 【工作感悟】 工作感悟-时间管理