已解决
文件转换,简简单单,pdf转word,不要去找收费的了,自己学了之后免费转,之后就复制粘贴就ok了
来自网友在路上 174874提问 提问时间:2023-11-19 23:55:23阅读次数: 74
最佳答案 问答题库748位专家为你答疑解惑
先上一个链接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>
经得起实操,不要怪我没有整理最终生成的格式,实在有些东西不好搞,只能放放了
查看全文
99%的人还看了
相似问题
- 使用opencv将sRGB格式的图片转换为BT.2020格式【sRGB】【BT.2020】
- YOLO目标检测——卫星遥感多类别检测数据集下载分享【含对应voc、coco和yolo三种格式标签】
- VMware 系列:戴尔服务器配置(格式数据、RAID5、安装ESXI)以及相关问题
- qcow2、raw、vmdk等镜像格式工具
- 微信小程序发货信息录入接口 错误上传时间非法,请按照 RFC 3339 格式填写?
- 2015-2020年全国地区生产总值及一二三产构成数据总览,shp/excel格式
- 媒体格式转换软件Permute 3 mac中文版软件特点
- 智能门禁刷脸照片格式gif、bmp,png转换,转换base64
- MAC地址_MAC地址格式_以太网的MAC帧_基础知识
- 硬盘无法格式化怎么办?
猜你感兴趣
版权申明
本文"文件转换,简简单单,pdf转word,不要去找收费的了,自己学了之后免费转,之后就复制粘贴就ok了":http://eshow365.cn/6-39774-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!
- 上一篇: Linux:常见指令
- 下一篇: C++学习 --vector