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; ...
随机推荐
- 关于UE5打包DLC
首先打开Project Lanucher,参考下图:,其次编辑配置两个edit Profile,参考下图: 第一个用来打包项目,第二个生成DLC,dlc填写的名字和插件一样,Main的配置如下: DL ...
- manim边学边做--Table
表格是一种常见的数据展示形式,manim提供了Table模块专门用于显示表格形式的数据.表格Table和上一节介绍的矩阵Matrix都是用来显示二维数据的,不过,Table的表现力更强,比如,它可以显 ...
- 1分钟了解HashSet的使用
前言:刷leetcode的时候体验到hashset有多厉害了,用了他剪枝之后直接不爆超时了.速度大大滴快 使用方法 1.创建set对象Set<Integer>set=new HashSet ...
- 【Hibernate】02 快速入门
环境搭建 : Windo7 x64 + IDEA 2018+ JDK 8+ Maven 3.0+ MySQL 5.0+ 创建Hibernate工程: 导入依赖坐标 <dependencies&g ...
- 阿里的镜像站不稳定如何解决——通过清华镜像站安装阿里的python包
最近在看阿里的python包,原因是为了看下阿里的modelscope服务,不过一个十分搞笑的一个事情,那就是阿里的python包在阿里网站上是访问不了的,只能换到其他镜像站来下载. 使用阿里的pyp ...
- error while loading shared libraries: libxml2.so.2: cannot open shared object file 解决方法
参考: https://blog.csdn.net/qq_39779233/article/details/128215517 ==================================== ...
- AI编程助手那些事儿
最近跟身边的程序员老杆子讨论需求时,惊奇的发现,他居然没使用AI编程助手.一时间有2个想法从大脑闪过,然后心里还带了一丝轻蔑: AI编程助手这么好的东西,你居然不用. 作为老程序员,你居然不跟上时代步 ...
- Apache DolphinScheduler如何开启开机自启动功能?
转载自东华果汁哥 Apache DolphinScheduler 是一个分布式.去中心化的大数据工作流调度系统,支持大数据任务调度.若要设置 DolphinScheduler 开机自启动,通常需要将其 ...
- 如何不用加法符号计算a+b 的值?
目前为止只有一种思路:位运算+递归小操作 a+b的值可以等价于a^b+(a&b)<<1,也就是a异或b的值加上a与b的值再左移一位.a异或b的值被叫做非进位求和,(a&b) ...
- 使用 defineNuxtRouteMiddleware 创建路由中间件
title: 使用 defineNuxtRouteMiddleware 创建路由中间件 date: 2024/8/10 updated: 2024/8/10 author: cmdragon exce ...