poi-tl设置图片(通过word模板替换关键字,然后转pdf文件并下载)
选中图片右击 选择设置图片格式



例如word模板

maven依赖
<!-- java 读取word文件里面的加颜色的字体 转pdf 使用 --><dependency><groupId> e-iceblue </groupId><artifactId>spire.doc.free</artifactId><version>3.9.0</version></dependency><!--poi 的相关组件 --><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml-schemas</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-scratchpad</artifactId><version>4.1.2</version></dependency><!-- 不添加此包会提示错误 : org.openxmlformats.schemas.wordprocessingml.x2006.main.FontsDocument$Factory --><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>org.apache.poi.xwpf.converter.pdf</artifactId><version>1.0.6</version></dependency><!-- 用于 word 转pdf --><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>xdocreport</artifactId><version>2.0.2</version></dependency><!-- pdf 添加水印 对PDF文件的操作 --><dependency><groupId>com.itextpdf</groupId><artifactId>itextpdf</artifactId><version>5.5.13.1</version></dependency><!-- PDF文件 字体 防止中文乱码 --><dependency><groupId>com.itextpdf</groupId><artifactId>itext-asian</artifactId><version>5.2.0</version></dependency><!--基于 poi实现word数据的替换 --><dependency><groupId>com.deepoove</groupId><artifactId>poi-tl</artifactId><version>1.9.1</version></dependency><!--如果下载jar失败,说明下载jar失败,需要以下的maven依赖[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException--> <repository><id>com.e-iceblue</id><url>http://repo.e-iceblue.cn/repository/maven-public/</url></repository></repositories><!-- <dependency><groupId>org.apache.pdfbox</groupId><artifactId>pdfbox</artifactId><version>2.0.25</version></dependency><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>org.apache.poi.xwpf.converter.xhtml</artifactId><version>1.0.6</version></dependency><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>fr.opensagres.xdocreport.document</artifactId><version>2.0.2</version></dependency><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>org.apache.poi.xwpf.converter.core</artifactId><version>1.0.6</version></dependency>--><!-- 打包使用,需要配置 --><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><!-- 打包时会将本地jar一起打包 --><configuration><includeSystemScope>true</includeSystemScope></configuration></plugin></plugins></build>
<!--基于 poi实现word数据的替换 --><dependency><groupId>com.deepoove</groupId><artifactId>poi-tl</artifactId><version>1.9.1</version></dependency><!-- 不添加此包会提示错误 : org.openxmlformats.schemas.wordprocessingml.x2006.main.FontsDocument$Factory --><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>org.apache.poi.xwpf.converter.pdf</artifactId><version>1.0.6</version></dependency><!-- 用于 word 转pdf --><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>xdocreport</artifactId><version>2.0.2</version></dependency>
读取

代码
@GetMapping("exportPDF")public AjaxResult exportPDF(HttpServletResponse response) throws Exception {LoginUser loginUser = getLoginUser();OpenCompanyInfo companyInfo = openCompanyInfoService.selectEnterpriseInfo(loginUser.getId());if (companyInfo != null) {Map<String, Object> data = new HashMap<>();data.put("legalDeputy", companyInfo.getLegalDeputy());data.put("companyName", companyInfo.getCompanyName());data.put("companyCode", companyInfo.getCompanyCode());if (StringUtils.isNoneBlank(companyInfo.getBusinessLicenseUrl())) {InputStream businessLicenseUrl = minioClientUtils.returnInputStream(null, companyInfo.getBusinessLicenseUrl());data.put("businessLicenseUrl", Pictures.ofStream(businessLicenseUrl, PictureType.JPEG).size(120, 120).create());}if (StringUtils.isNoneBlank(companyInfo.getCompanyLogoUr())) {InputStream companyLogoUrl = minioClientUtils.returnInputStream(null, companyInfo.getCompanyLogoUr());data.put("companyLogoUrl", Pictures.ofStream(companyLogoUrl, PictureType.JPEG).size(120, 120).create());}InputStream inputStreamFile = ResourceReader.class.getResourceAsStream("/templates/模版.docx");XWPFTemplate template = XWPFTemplate.compile(inputStreamFile).render(data);
// XWPFTemplate template = XWPFTemplate.compile("C:\\Users\\11949\\Desktop\\模版.docx").render(data);byte[] array = null;ByteArrayOutputStream baos = new ByteArrayOutputStream();template.writeAndClose(baos);array = baos.toByteArray();baos.close();template.close();InputStream inputStream = new ByteArrayInputStream(array);ByteArrayOutputStream pdfBaos = new ByteArrayOutputStream();XWPFDocument xwpfDocument = new XWPFDocument(inputStream);fr.opensagres.poi.xwpf.converter.pdf.PdfConverter.getInstance().convert(xwpfDocument, pdfBaos, PdfOptions.create());inputStream.close();xwpfDocument.close();response.setContentType("application/octet-stream");String format = DateUtil.format(new Date(), "yyyy-MM-dd");response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("认证授权函" + format + ".pdf", "UTF-8"));OutputStream out = response.getOutputStream();BufferedOutputStream bos = new BufferedOutputStream(out);pdfBaos.writeTo(bos);bos.flush();out.flush();PoitlIOUtils.closeQuietlyMulti(template, bos, out);}return null;}
相关文章:
poi-tl设置图片(通过word模板替换关键字,然后转pdf文件并下载)
选中图片右击 选择设置图片格式 例如word模板 maven依赖 <!-- java 读取word文件里面的加颜色的字体 转pdf 使用 --><dependency><groupId> e-iceblue </groupId><artifactId>spire.doc.free</artifactId><version>3.9.0</ver…...
[element-ui] el-tree 懒加载load
懒加载:点击节点时才进行该层数据的获取。 注意:使用了懒加载之后,一般情况下就可以不用绑定:data。 <el-tree :props"props" :load"loadNode" lazy></el-tree>懒加载—由于在点击节点时才进行该层数据的获取…...
【C++】使用 nlohmann 解析 json 文件
引言 nlohman json GitHub - nlohmann/json: JSON for Modern C 是一个为现代C(C11)设计的JSON解析库,主要特点是 易于集成,仅需一个头文件,无需安装依赖 易于使用,可以和STL无缝对接,使用体验…...
Nginx到底是什么,他能干什么?
目录 Ngnix是什么,它是用来做什么的呢? 一。Nginx简介 二,为什么要用Nginx呢? 二。Nginx应用 1.HTTP代理和反向代理 2.负载均衡 Ngnix是什么,它是用来做什么的呢? 一。Nginx简介 Nginx是enginex的简写&…...
如何判断一个java对象还活着
引用计数算法 引用计数器的算法是这样的:在对象中添加一个引用计数器,每当有一个地方引用它时,计数器值就加一;当引用失效时,计数器值就减一;任何时刻计数器为零的对象就是不可能再被使用的。 缺点&#x…...
Go语言基础之结构体
Go语言中没有“类”的概念,也不支持“类”的继承等面向对象的概念。Go语言中通过结构体的内嵌再配合接口比面向对象具有更高的扩展性和灵活性。 类型别名和自定义类型 自定义类型 在Go语言中有一些基本的数据类型,如string、整型、浮点型、布尔等数据…...
前端食堂技术周刊第 96 期:2023 CSS 状态、Nuxt 3.7、TypeScript 5.2、eBay 性能优化、贝塞尔曲线
美味值:🌟🌟🌟🌟🌟 口味:冰镇黑乌龙 食堂技术周刊仓库地址:https://github.com/Geekhyt/weekly 大家好,我是童欧巴。欢迎来到前端食堂技术周刊,我们先来看…...
一文总结Redis知识点
目录 为什么基于MySQL又出现Redis?Redis的优点?Redis支持的基本命令Redis支持的数据结构1 String2 List3 Set4 Sorted Set5 Hash6 Stream 消息队列7 Geospatial 地理空间8 Bitmap 位图9 Bitfield 位域10 HyperLogLog Redis是单线程还是多线程?…...
ARM寄存器组
CM3 拥有通用寄存器 R0‐R15 以及一些特殊功能寄存器。 R0-R7,通用目的寄存器 R0-R7也被称为低组寄存器,所有指令可以访问它们,它们的字长为32位,复位后的初始值是不可预料的。 R8-R12,通用目的寄存器 R8-R12也被称…...
Windows查看当前文件夹下的所有.c文件的个数
在Windows的命令提示符(CMD)中,你可以使用for循环和dir命令结合起来,以计算当前文件夹下所有 .c 文件的个数。 下面是一个简单的示例,这个批处理脚本会计算当前目录下所有 .c 文件的个数: echo off setlo…...
ubuntu Qt 地图离线调用
ubuntu环境下在Qt上调用百度地图_ubuntu 百度地图_拿到金像奖上课那家店的博客-CSDN博客 【Qt初入江湖】Qt QtWebEngineWidgets 底层架构、原理详细描述_鱼弦的博客-CSDN博客 Ubuntu20.04 QT无法用Qwebengine控件的解决方案(临时)_cmsyq的博客-CSDN博客…...
Android Studio升级到Android API 33版本后,XML布局输入没有提示
低版本的Android Studio升级到Android API 33版本后,XML布局输入没有提示。查一下我目前使用的Android Studio 是2021年发布,而Android API 33是2022年发布的,这是由低版本升级到高版本造成不兼容的问题。解决方法有两种: 第一种…...
操作XML(带命名空间)
之前文章讲述了使用c# xpath如何操作xml文件,在实际开发项目中,遇到的很多xml文件都是带有命名空间的,如果还是用之前的代码获取,那将获取到null。 本文讲解操作代码有命名空间的Xml文件,以及多个命名空间的xml。 <…...
二叉搜索树(C++)
二叉搜索树 概念二叉搜索树的应用二叉搜索树的实现K模型基本结构和函数声明接口实现①find——查找关键码②Insert——插入关键码③Erase——删除关键码(重点)时间复杂度 源码(整体)非递归递归 KV模型 在使用C语言写数据结构阶段时…...
软件架构知识点
常用软件架构模型分类(5种) 软件架构建模方法(模型4种) 架构师分类(微软4种) 系统架构设计师的角色特质(6种) 计算机系统组成图谱 嵌入式操作系统的特点(5个&#x…...
C语言日常刷题6
文章目录 题目答案与解析1234567 题目 1、以下对C语言函数的有关描述中,正确的有【多选】( ) A: 在C语言中,一个函数一般由两个部分组成,它们是函数首部和函数体 B: 函数的实参和形参可以是相同的名字 C: 在main()中定…...
微信小程序使用stomp.js实现STOMP传输协议的实时聊天
简介: uniapp开发的小程序中使用 本来使用websocket,后端同事使用了stomp协议,导致前端也需要对应修改。 如何使用 在static/js中新建stomp.js和websocket.js,然后在需要使用的页面引入监听代码发送代码即可 代码如下&#x…...
基于饥饿游戏算法优化的BP神经网络(预测应用) - 附代码
基于饥饿游戏算法优化的BP神经网络(预测应用) - 附代码 文章目录 基于饥饿游戏算法优化的BP神经网络(预测应用) - 附代码1.数据介绍2.饥饿游戏优化BP神经网络2.1 BP神经网络参数设置2.2 饥饿游戏算法应用 4.测试结果:5…...
[ 云计算 | AWS ] Java 应用中使用 Amazon S3 进行存储桶和对象操作完全指南
文章目录 一、前言二、所需 Maven 依赖三、先决必要的几个条件信息四、创建客户端连接五、Amazon S3 存储桶操作5.1. 创建桶5.2. 列出桶 六、Amazon S3 对象操作6.1. 上传对象6.2. 列出对象6.3. 下载对象6.4. 复制、重命名和移动对象6.5. 删除对象6.6. 删除多个对象 七、文末总…...
【Spring Boot】Spring Boot 配置 Hikari 数据库连接池
文章目录 前言配置 前言 数据库连接池是一个提高程序与数据库的连接的优化,连接池它主要作用是提高性能、节省资源、控制连接数、连接管理等操作; 程序中的线程池与之同理,都是为了优化、提高性能。 配置 spring:datasource:hikari:# 设置是…...
mongodb源码分析session执行handleRequest命令find过程
mongo/transport/service_state_machine.cpp已经分析startSession创建ASIOSession过程,并且验证connection是否超过限制ASIOSession和connection是循环接受客户端命令,把数据流转换成Message,状态转变流程是:State::Created 》 St…...
鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个医院挂号小程序
一、开发准备 环境搭建: 安装DevEco Studio 3.0或更高版本配置HarmonyOS SDK申请开发者账号 项目创建: File > New > Create Project > Application (选择"Empty Ability") 二、核心功能实现 1. 医院科室展示 /…...
【android bluetooth 框架分析 04】【bt-framework 层详解 1】【BluetoothProperties介绍】
1. BluetoothProperties介绍 libsysprop/srcs/android/sysprop/BluetoothProperties.sysprop BluetoothProperties.sysprop 是 Android AOSP 中的一种 系统属性定义文件(System Property Definition File),用于声明和管理 Bluetooth 模块相…...
鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个生活电费的缴纳和查询小程序
一、项目初始化与配置 1. 创建项目 ohpm init harmony/utility-payment-app 2. 配置权限 // module.json5 {"requestPermissions": [{"name": "ohos.permission.INTERNET"},{"name": "ohos.permission.GET_NETWORK_INFO"…...
Unit 1 深度强化学习简介
Deep RL Course ——Unit 1 Introduction 从理论和实践层面深入学习深度强化学习。学会使用知名的深度强化学习库,例如 Stable Baselines3、RL Baselines3 Zoo、Sample Factory 和 CleanRL。在独特的环境中训练智能体,比如 SnowballFight、Huggy the Do…...
Redis的发布订阅模式与专业的 MQ(如 Kafka, RabbitMQ)相比,优缺点是什么?适用于哪些场景?
Redis 的发布订阅(Pub/Sub)模式与专业的 MQ(Message Queue)如 Kafka、RabbitMQ 进行比较,核心的权衡点在于:简单与速度 vs. 可靠与功能。 下面我们详细展开对比。 Redis Pub/Sub 的核心特点 它是一个发后…...
C#中的CLR属性、依赖属性与附加属性
CLR属性的主要特征 封装性: 隐藏字段的实现细节 提供对字段的受控访问 访问控制: 可单独设置get/set访问器的可见性 可创建只读或只写属性 计算属性: 可以在getter中执行计算逻辑 不需要直接对应一个字段 验证逻辑: 可以…...
怎么让Comfyui导出的图像不包含工作流信息,
为了数据安全,让Comfyui导出的图像不包含工作流信息,导出的图像就不会拖到comfyui中加载出来工作流。 ComfyUI的目录下node.py 直接移除 pnginfo(推荐) 在 save_images 方法中,删除或注释掉所有与 metadata …...
MySQL 主从同步异常处理
阅读原文:https://www.xiaozaoshu.top/articles/mysql-m-s-update-pk MySQL 做双主,遇到的这个错误: Could not execute Update_rows event on table ... Error_code: 1032是 MySQL 主从复制时的经典错误之一,通常表示ÿ…...
【C++】纯虚函数类外可以写实现吗?
1. 答案 先说答案,可以。 2.代码测试 .h头文件 #include <iostream> #include <string>// 抽象基类 class AbstractBase { public:AbstractBase() default;virtual ~AbstractBase() default; // 默认析构函数public:virtual int PureVirtualFunct…...
