当前位置: 首页 > news >正文

北京疫情防控最新消息南宁seo排名收费

北京疫情防控最新消息,南宁seo排名收费,合肥昱天建设有限公司网站,广州外贸网站建设公司java itext5 生成PDF并填充数据导出 依赖**文本勾选框****页眉**&#xff0c;**页脚****图片**实际图 主要功能有文本勾选框&#xff0c;页眉&#xff0c;页脚&#xff0c;图片等功能。肯定没有专业软件画的好看&#xff0c;只是一点儿方法。仅供参考。 依赖 <!--pdf-->&…

java itext5 生成PDF并填充数据导出

  • 依赖
  • **文本勾选框**
  • **页眉**,**页脚**
  • **图片**
  • 实际图

主要功能有文本勾选框页眉页脚图片等功能。肯定没有专业软件画的好看,只是一点儿方法。仅供参考。

依赖

        <!--pdf--><dependency><groupId>com.itextpdf</groupId><artifactId>itextpdf</artifactId><version>5.5.13</version></dependency><dependency><groupId>com.itextpdf</groupId><artifactId>itext-asian</artifactId><version>5.2.0</version></dependency>

文本勾选框

生成勾选框的图片,将图片插入到文本前面

private static Image checkBoxPng;static {ClassPathResource classPathResource = new ClassPathResource(CHECK_BOX_PATH);try {byte[] byteArray = FileCopyUtils.copyToByteArray(classPathResource.getInputStream());checkBoxPng = Image.getInstance(byteArray);} catch (IOException | BadElementException e1) {e1.printStackTrace();}}-------------------------------------------------------------------------final Paragraph paragraph = new Paragraph();if (checkBox != null && checkBox) {try {
//				final Image png = Image.getInstance(CHECK_BOX_PATH);// y轴 向下偏移5 保证大致上都是水平的final Chunk chunk = new Chunk(checkBoxPng, 0, -5);paragraph.add(chunk);} catch (Exception e) {throw new BusinessException(e.getMessage());}}paragraph.add(new Phrase(value, font));

页眉页脚

itext5没有页眉页脚设置的api,所以用的是定位的方式;
new Document();时预留出页眉和页脚数据所需要的空间大小
pdfPTable.writeSelectedRows(); 定位的方式把表格定位到对应的位置上即可

@Slf4j
@Component
public abstract class HeaderFooterEventHelper extends PdfPageEventHelper {/*** 页眉*/protected final List<CustomExportTemplateModuleDTO> headerList;/*** 页脚*/protected final List<CustomExportTemplateModuleDTO> footerList;public HeaderFooterEventHelper(List<CustomExportTemplateModuleDTO> headerList,List<CustomExportTemplateModuleDTO> footerList) {this.headerList = headerList;this.footerList = footerList;}/*** 一页加载完成触发,写入页眉和页脚*/@Overridepublic abstract void onEndPage(PdfWriter writer, Document document);
}
		//移除边距 方便设置页眉和页脚  定制页眉页脚Document document = new Document(PageSize.A4,-30 + ObjectUtils.defaultIfNull(module.getLeftMargin(), 0),-30 + ObjectUtils.defaultIfNull(module.getRightMargin(), 0),// 页眉高度 + 间隙高度  /页脚高度 - 间隙高度 (页面底部有一部分真空区域)headerSize + GAP_SIZE + ObjectUtils.defaultIfNull(module.getUpMargin(), 0),footerSize + GAP_SIZE + ObjectUtils.defaultIfNull(module.getDownMargin(), 0));ByteArrayOutputStream baos = new ByteArrayOutputStream();final PdfWriter writer = PdfWriter.getInstance(document, baos);// 初始化 页眉、页脚数据体writer.setPageEvent(new HeaderFooterEventHelper(headerDTOS, footerDTOS) {@Overridepublic void onEndPage(PdfWriter writer, Document document) {final ICustomExportTemplateService customExportTemplateService = SpringContextUtil.getBean(ICustomExportTemplateService.class);if (customExportTemplateService != null) {customExportTemplateService.setPdfData(this.headerList, writer, ZERO);customExportTemplateService.setPdfData(this.footerList, writer, ONE);}}});-------------------------------------------------------------------
@Overridepublic void setPdfData(List<CustomExportTemplateModuleDTO> moduleDTOS, PdfWriter writer, Integer type) {float size = 0;final float sumSize = getSumSize(moduleDTOS);for (CustomExportTemplateModuleDTO item : moduleDTOS) {PdfPTable pdfPTable; // 创建的表格pdfPTable.setTotalWidth(PageSize.A4.getWidth());pdfPTable.setWidthPercentage(WIDTH_PERCENT);if (Objects.equals(type, ZERO)) {// 页眉 基点为 左下角0点 高度为 A4全高 - 使用高度pdfPTable.writeSelectedRows(0, -1, ZERO,PageSize.A4.getHeight() - size, writer.getDirectContent());} else if (Objects.equals(type, ONE)) {// 页脚 基点为 左下角0点 高度为 列表使用总高度 - 使用高度pdfPTable.writeSelectedRows(0, -1, ZERO,sumSize - size, writer.getDirectContent());}if (item.getLabel().equals(2)) {size += BigDecimal.valueOf(item.getData().size()).multiply(BigDecimal.valueOf(CELL_SIZE)).intValue();} else {// 默认每行高度为 25size += CELL_SIZE;}}}

图片

PdfPCell cell = new PdfPCell();
// 我这里是根据文件服务器上的图片链接进行获取的。
cell.setImage(Image.getInstance(MinioUtil.getUrlName(imageUrl)));

实际图

http://www.mmbaike.com/news/99876.html

相关文章:

  • 齐家网装修公司口碑北京seo主管
  • wordpress虚线框河北seo关键词排名优化
  • ftp工具下载网站源码教程怎么样关键词优化
  • 网站建设柒首先金手指6百度官方网页版
  • 想在意大利做购物网站网店怎么运营和推广
  • 龙湾区建设局的网站八百客crm登录入口
  • 苏州做外贸网站广告联盟平台哪个好
  • 多少钱可以做网站信息发布推广平台
  • 蓝月wordpress南宁市优化网站公司
  • 毕业生就业网站开发项目外贸网站推广软件
  • 柬埔寨美女教你用母乳做奶茶原网站怎么看app的下载网址
  • 营业执照年检入口天津seo公司
  • 潍坊市奎文建设局网站网络公司推广方案
  • 中国建筑招聘官网2022seo查询软件
  • 设计导航网站 左侧菜单栏制作app软件平台
  • 网站建设 福步 2018常用网站推广方法及资源
  • 域名怎么绑定自己网站成品网站货源1688在线
  • 建站平台塔山双喜培训班招生方案
  • ecs服务器 做网站郑州专业seo首选
  • appcan 手机网站开发网络营销有哪几种方式
  • 网站建设积分百度知道官网
  • 微网站注册广州百度推广优化
  • 深圳新站优化河南靠谱seo地址
  • 做外贸国外网站创建自己的网站怎么弄
  • 3合1网站建设价格湖南网站优化
  • 空滤网站怎么做平台怎么推广技巧
  • 农产品网站开发背景新品上市怎么推广词
  • 怎么用宝塔做网站百度竞价推广出价技巧
  • 做电商网站需要多少时间seo引擎优化是什
  • 珠海企业集团网站建设天津seo网站排名优化公司