Java poi 读取 word 、 pdf
从各个博客 CV 出来的,不好意思
pom
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.21</version>
</dependency>
<!--读取pdf信息-->
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.pdfbox/fontbox -->
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>fontbox</artifactId>
<version>2.0.12</version>
</dependency>
按段落 读取 docx
@SneakyThrows
private void readDocx(MultipartFile file) {
InputStream inputStream = file.getInputStream();
XWPFDocument document = new XWPFDocument(inputStream);
// 读取段落
List<XWPFParagraph> paragraphs = document.getParagraphs();
List<WordFileInfo> infos = new ArrayList<>();
for (XWPFParagraph paragraph : paragraphs) {
String text = paragraph.getParagraphText();
}
}
按段落 读取 doc
@SneakyThrows
private void readDoc(MultipartFile file) {
InputStream inputStream = file.getInputStream();
HWPFDocument document = new HWPFDocument(inputStream);
Range range = document.getRange();
List<WordFileInfo> infos = new ArrayList<>();
for (int i = 0; i < range.numParagraphs(); i++) {
Paragraph paragraph = range.getParagraph(i);
String text = paragraph.text();
}
}
读取 pdf
/**
* 读取 pdf 文件内容
*
* @param inputStream
* @return
*/
private String readPDF(InputStream inputStream) {
StringBuilder content = new StringBuilder();
try {
RandomAccessBuffer buffer = new RandomAccessBuffer(inputStream);
PDFParser pdfParser = new PDFParser(buffer);
pdfParser.parse();
PDDocument document = pdfParser.getPDDocument();
// 获取页码
int pages = document.getNumberOfPages();
PDFTextStripper stripper = new PDFTextStripper();
// 设置按顺序输出
stripper.setSortByPosition(true);
stripper.setStartPage(1);
stripper.setEndPage(pages);
content.append(stripper.getText(document));
} catch (Exception e) {
e.printStackTrace();
}
return content.toString();
}
Java poi 读取 word 、 pdf的更多相关文章
- Java POI 读取word文件
Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. 1.读取word 2003及word 2007需要 ...
- java使用poi读取word(简单,简约,直观)
java使用poi读取word(简单,简约,直观) 说明 其实poi的官网上面都是有接口和样例的,只是都是英文 例如网址:http://poi.apache.org/spreadsheet/quick ...
- POI 读取word (word 2003 和 word 2007) (转)
最近在给客户做系统的时候,用户提出需求,要能够导入 word 文件,现在 microsoft word 有好几个版本 97.2003.2007的,这三个版本存储数据的格式上都有相当大的差别,而现在 9 ...
- POI 读取word (word 2003 和 word 2007)(转,好用)
POI 读取word (word 2003 和 word 2007)(转,好用) 转做的操作: 将作者文中失效的链接的正确链接放在失效链接的下面. 最近在给客户做系统的时候,用户提出需求,要能够导入 ...
- Java poi读取,写入Excel2003
Java poi读取,写入Excel2003 相关阅读:poi读写Excel2007:http://www.cnblogs.com/gavinYang/p/3576741.htmljxl读写excel ...
- Java poi读取,写入Excel2007
Java poi读取,写入Excel2007 相关阅读:poi读写Excel2003:http://www.cnblogs.com/gavinYang/p/3576739.htmljxl读写excel ...
- java 使用poi读取word文档存入数据库
使用的poi jar包需要自己下载 读取的word文档中含有多个图片,所以分为两个部分,一个部分读取各个表格中内容,一个是将所有图片截取出来: /** * 遍历段落内容 * docxReadPath ...
- Java POI 解析word文档
实现步骤: 1.poi实现word转html 2.模型化解析html 3.html转Map数组 Map数组(数组的操作处理不做说明) 1.导jar包. 2.代码实现 package com.web.o ...
- poi读取word的内容
pache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. 1.读取word 2003及word 2007需要的 ...
- java中读取word文档里的内容
package com.cn.peitest.excel.word; import java.io.FileInputStream; import java.io.FileOutputStream; ...
随机推荐
- 广州大学第十八届ACM大学生程序设计竞赛(同步赛)——题解
这套题我答的很失败.没有按照题目的难度去答题,前期浪费了不少时间. 题目: A-字符画 题解:思维.模拟.这道题我的通过率为62.5,没有过的原因是因为对细节的处理和把控不到位,对一些点忽视,我也记录 ...
- java开发环境安装IDEA+jdk1.8
一. 需要得安装包 (1)IDEA破解版.zip (2)jdk1.8.0_25.7z 获取方式(免费): (1) 登录-注册:http://resources.kittytiger.cn/ ...
- 通过程序名称kill掉所有的进程
通过程序名称kill掉所有的进程 今天差点把服务器搞崩了. 脚本的循环条件有问题,结果起了无数的nslookup,用pkill杀不掉,只能用kill一个个解决,服务器还被搞得慢得要命. 还好又黄队长, ...
- Bulk RNA-seq 基本分析流程
目的: 对illumina数据进行处理,利用 RNA-Seq 发现新的 RNA 变体和剪接位点,或量化 mRNA 以进行基因表达分析等.对两组或多组样本的转录组数据,通过差异表达分析和对所发现的差异表 ...
- 【TypeScript】Re01
参考视频: https://www.bilibili.com/video/BV14Z4y1u7pi JS已有类型: 基础类型 number / string / boolean / null / un ...
- 【Kafka】02 原生集群部署
基于大数据教程的环境: 192.168.101.11 centos7-01 192.168.101.12 centos7-02 192.168.101.13 centos7-03 搭建Kafka环境需 ...
- 【RabbitMQ】10 深入部分P3 死信队列(交换机)
1.死信交换机 说是死信队列,是因为RabbitMQ和其他中间件产品不一样 有交换机的概念和这个东西存在,别的产品只有队列一说 DeadLetterExchange 消息成为DeadMessage之后 ...
- OpenCV计算机视觉学习(16)——仿射变换学习笔记
如果需要其他图像处理的文章及代码,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/ComputerVisionPractic ...
- 基于SiliconCloud快速体验GraphRag.Net
SiliconCloud介绍 SiliconCloud 基于优秀的开源基础模型,提供高性价比的 GenAI 服务. 不同于多数大模型云服务平台只提供自家大模型 API,SiliconCloud上架了包 ...
- 【VMware vCenter】一次性说清楚 vCenter Server 的 CLI 部署方式。
VMware vCenter Server 是 VMware vSphere 解决方案的核心组件,用于管理多个 ESXi 主机并实现更多高级功能特性(如 HA.DRS 以及 FT 等),相信大家已经非 ...