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

文件转换,简简单单,pdf转word,不要去找收费的了,自己学了之后免费转,之后就复制粘贴就ok了

先上一个链接pdf转word文件转换

接口层

@PostMapping("pdfToWord")public String  pdfToWord(@RequestParam("file") MultipartFile file) throws IOException {String fileName = FileExchangeUtil.pdfToWord(file.getInputStream(),file.getName());return fileName;}

方法层-----一个方法直接搞定

  /*** 只是单纯的文字转换,没有任何的格式** @param inputStream 文件流* @return*/public static String pdfToWord(InputStream inputStream, String fileName) {//创建一个堆系pdf对象PDDocument document = null;FileOutputStream outputStream = null;if (Objects.isNull(fileName)) {fileName = FileExchangeUtil.getRandomString();}try {document = PDDocument.load(inputStream);PDFTextStripper stripper = new PDFTextStripper();//获取文本内容String text = stripper.getText(document);//创建word文档XWPFDocument doc = new XWPFDocument();XWPFParagraph p = doc.createParagraph();XWPFRun r = p.createRun();r.setText(text);//保存wordoutputStream = new FileOutputStream(new File("./file/"+fileName + ".docx"));doc.write(outputStream);} catch (IOException e) {e.printStackTrace();try {outputStream.close();} catch (IOException ioException) {ioException.printStackTrace();return null;}return null;}return fileName;}

需要的依赖

 <dependency><groupId>com.alibaba.fastjson2</groupId><artifactId>fastjson2</artifactId><version>2.0.40</version></dependency><!-- https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter --><dependency><groupId>io.springfox</groupId><artifactId>springfox-boot-starter</artifactId><version>3.0.0</version></dependency><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>29.0-jre</version></dependency><dependency><groupId>org.apache.pdfbox</groupId><artifactId>pdfbox</artifactId><version>2.0.4</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>4.1.2</version></dependency>

经得起实操,不要怪我没有整理最终生成的格式,实在有些东西不好搞,只能放放了

http://www.lryc.cn/news/236166.html

相关文章:

  • Jmeter——循环控制器中实现Counter计数器的次数重置
  • [创业之路-85]:IT创业成功老板的品质、创业失败老板的特征、成功领导者的品质、失败管理者的特征
  • 警惕.360勒索病毒,您需要知道的预防和恢复方法。
  • 人力资源小程序
  • 【多线程 - 10、线程同步3 ThreadLocal】
  • 【Flink 问题集】The generic type parameters of ‘Collector‘ are missing
  • 数据分析—将txt文件转为csv文件;将csv文件转为xls文件
  • 【算法】二分查找-20231120
  • WPF实现将鼠标悬浮在按钮上时弹出菜单
  • 车载以太网-传输层-UDP
  • uniapp如何上传文件,使用API是什么
  • 【狂神说Java】Docker概述 | Docker安装 | Docker的常用命令
  • Git精讲
  • 读书笔记:Effective C++ 3.0版2005年Scott Meyers : 55条建议(47-55)
  • Golang Context 的并发安全性探究
  • C++中只能有一个实例的单例类
  • 单张图像3D重建:原理与PyTorch实现
  • 340条样本就能让GPT-4崩溃,输出有害内容高达95%?OpenAI的安全防护措施再次失效
  • 2023.11.17使用flask将多个图片文件上传至服务器
  • 母婴服务预约小程序的效果如何
  • Flask实现cookie 开发
  • 2311rust,到60版本更新
  • 【开源】基于Vue和SpringBoot的微信小程序的音乐平台
  • adb手机调试常用命令
  • IDEA常用插件合集
  • 【算法】滑动窗口题单——2.不定长滑动窗口(求最长/最大)
  • 电子学会C/C++编程等级考试2022年03月(一级)真题解析
  • Libvirt-Qemu-Kvm 操作手记
  • 代码随想录算法训练营第二十八天| 78 子集 90 子集|| 93 复原IP地址
  • 9 HDFS架构剖析