首先功能需要准备的依赖包:
aspose-words-15.8.0-jdk16.jar

  <dependency><groupId>com.aspose.words</groupId><artifactId>aspose-words-jdk15</artifactId><version>15.8.0</version></dependency>
public class FileUtil {public static File getFileStream(String fileName) {//获取项目路径String url="F:/test/";//文件路径String docPath = url+fileName;//String docPath = "D://" + fileName;if (!new File(docPath).exists()) {return null;}String str[] = docPath.split("[.]");if (str[str.length-1]=="pdf"){return new File(docPath);}String pdfName = docPath.replace(str[str.length-1],"pdf");System.out.println(pdfName);File pdfFile = new File(pdfName);try {ResourceLoader resourceLoader=new DefaultResourceLoader();String location="/Aspose.Words.lic";//获取resource包下的Aspose.Words.lic文件InputStream inputStream = resourceLoader.getResource(location).getInputStream();License aposeLic = new License();aposeLic.setLicense(inputStream);Document document = new Document(docPath);document.save(new FileOutputStream(pdfFile), SaveFormat.PDF);} catch (Exception e) {e.printStackTrace();}if (!pdfFile.exists()) {return null;}return pdfFile;}
}serviceImpl层实现@Overridepublic Map<String, Object> getFileStream(HttpServletResponse response, String fileName) {File pdfFile = null;OutputStream outputStream = null;BufferedInputStream bufferedInputStream = null;
//          String docPath = fileName + ".doc";
//          String pdfPath = fileName + ".pdf";try {//获取生成的pdfpdfFile = FileUtil.getFileStream(fileName);outputStream = response.getOutputStream();response.setContentType("application/pdf;charset=UTF-8");bufferedInputStream = new BufferedInputStream(new FileInputStream(pdfFile));byte buffBytes[] = new byte[1024];outputStream = response.getOutputStream();int read = 0;//docx||doc文档流写入pdf文件while ((read = bufferedInputStream.read(buffBytes)) != -1) {outputStream.write(buffBytes, 0, read);}} catch (ConnectException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}  finally {if(outputStream != null){try {outputStream.flush();outputStream.close();} catch (IOException e) {e.printStackTrace();}}if(bufferedInputStream != null){try {bufferedInputStream.close();} catch (IOException e) {e.printStackTrace();}}}return null;}//创建一个Aspose.Words.lic放在resource下即可
```java
"<License>
<Data>
<Products>
<Product>Aspose.Total for Java</Product>
<Product>Aspose.Words for Java</Product>
</Products>
<EditionType>Enterprise</EditionType>
<SubscriptionExpiry>20991231</SubscriptionExpiry>
<LicenseExpiry>20991231</LicenseExpiry>
<SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>
</Data>
<Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>
</License>"

需要依赖包可以
链接:https://pan.baidu.com/s/1Z4UHFMThaEj4D7Phbq7R3w
提取码:s18s

springboot实现word转pdf相关推荐

  1. 【技术】基于 SpringBoot实现 Word 和 PDF 识别

    基于 SpringBoot实现 Word 和 PDF 识别 基于 SpringBoot 实现 Word 和 PDF 识别 识别 Word 识别 PDF 基于 SpringBoot 实现 Word 和 ...

  2. springboot+Elasticsearch实现word,pdf,txt内容抽取并高亮分词全文检索

    文章目录 需求 一.环境 二.功能实现 1.搭建环境 2.文件内容识别 三.代码 需求 产品希望我们这边能够实现用户上传PDF,WORD,TXT之内得文本内容,然后用户可以根据附件名称或文件内容模糊查 ...

  3. libreoffice + jodconverter + Springboot 整合使用将Word转PDF

    libreoffice + jodconverter + Springboot 整合使用将Word转PDF 第一步 安装Libreoffice https://jingyan.baidu.com/ar ...

  4. SpringBoot根据模板生成Word文件,然后Word转PDF

    1.在pom文件中导入相关依赖 <!--根据模板生成Word 需要依赖 开始--><dependency><groupId>cn.afterturn</gro ...

  5. springboot操作pdf(一)之word转pdf

    文章目录 前言 一.PDF是什么? 二.解决方案 1.方案一:使用POI工具,将word文件转化成pdf 1.1 导入依赖 1.2 代码如下(示例) 1.3 缺点 2.使用spire.doc.free ...

  6. Springboot使用itext及documents4j操作pdf(word转pdf、pdf加水印(文字或图片,可指定位置)、pdf加密(打开密码,编辑密码))

    pom.xml引入 <!-- pdf文档生成 --><dependency><groupId>com.documents4j</groupId>< ...

  7. Aspose.Java实现word转pdf,添加水印等操作

    Aspose.Java实现word转pdf,添加水印等操作 一. word转pdf 二. 文档插入水印 Aspose是一款商用版控件,支持各类文档操作,这里主要介绍如何在Springboot项目中使用 ...

  8. SpringBoot+FreeMarker+flying-saucer-pdf实现PDF预览、分页需求

    文章目录 SpringBoot+FreeMarker+flying-saucer-pdf实现PDF预览.分页需求 需求说明 程序示例 程序示例说明 添加依赖包 FreeMarker模板文件编写 工具类 ...

  9. 推荐一款word转pdf超好用的包:aspose-words(解决中文乱码)

    aspose-words 是一款超好用的转换工具,转换效果很好,且实现超级简单 首先通过pom.xml 引入 <dependency><groupId>com.aspose&l ...

  10. Java后端生成Echarts并渲染Word转PDF

    生成pdf文件 文件要素 文件中包含图片 文件中包含列表 文件中包含表格 文件中包含循环嵌套写入的内容 文件需要后端生成echarts图表数据 基于以上几点考虑 技术选取 方式一 itext7是一款用 ...

最新文章

  1. 如何在C ++中从容器中删除元素
  2. 第一次作业:阅读优秀博文谈感想
  3. 如何使用webrtc 一
  4. 你身边有没有“万事不求人”的人?他们后来怎么样了?
  5. L2-005 集合相似度(STL+暴力)
  6. 142.PHP session 阻塞问题
  7. 计算机网络(北京理工大学出版社)课后习题答案
  8. 输入等值线参数绘制等值线图python_专题复习:等值线(上)
  9. 国外问卷调查赚钱网站
  10. .NET利用ActionFilter特性记录日志或者运行性能计数器。(log trace or perform perfcounter by actionFilter attribute)...
  11. web网站添加ico图标
  12. 网页打开慢的服务器网络原因,网页打开很慢的原因有哪些 如何处理
  13. 图片怎么修改尺寸大小?在线调整图像大小的方法
  14. SpringBoot 轻松搞定数据验证 (二)
  15. 【算法思路】常见岛屿数量的算法题
  16. HTML5输入框里加图片代码,做了一个input上传加号框,图片上传后显示在框中,怎么让加号消失?...
  17. 解决启动MySql时出现 2003 - Can't connect to MySQL server on '127.0.0.1'(10038)问题
  18. Java获取某年某周的第一天
  19. hmailserver配置(图)
  20. word、wps中使用vba删除所有表格指定列

热门文章

  1. Abp 添加阿里云短信发送
  2. 【评分】软件工程实践2017第一次作业-准备
  3. 联邦学习(Federated Learning)学习小记
  4. 安信可经验分享 | WiFi保持连接状态下低功耗的实现,适用于ESP32/ESP32C3/ESP32S3系列模组二次开发
  5. 百度富文本编辑器配置使用
  6. 激光雷达考试基础知识
  7. 三国志战略版:先锋斥候广州行
  8. 我收藏的thinkphp扩展插件
  9. bip动作捕捉_Easy Mocap
  10. 微信小程序Cede获取 PC电脑版微信实现Code的获取