从各个博客 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的更多相关文章

  1. Java POI 读取word文件

    Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. 1.读取word 2003及word 2007需要 ...

  2. java使用poi读取word(简单,简约,直观)

    java使用poi读取word(简单,简约,直观) 说明 其实poi的官网上面都是有接口和样例的,只是都是英文 例如网址:http://poi.apache.org/spreadsheet/quick ...

  3. POI 读取word (word 2003 和 word 2007) (转)

    最近在给客户做系统的时候,用户提出需求,要能够导入 word 文件,现在 microsoft word 有好几个版本 97.2003.2007的,这三个版本存储数据的格式上都有相当大的差别,而现在 9 ...

  4. POI 读取word (word 2003 和 word 2007)(转,好用)

    POI 读取word (word 2003 和 word 2007)(转,好用) 转做的操作: 将作者文中失效的链接的正确链接放在失效链接的下面. 最近在给客户做系统的时候,用户提出需求,要能够导入 ...

  5. Java poi读取,写入Excel2003

    Java poi读取,写入Excel2003 相关阅读:poi读写Excel2007:http://www.cnblogs.com/gavinYang/p/3576741.htmljxl读写excel ...

  6. Java poi读取,写入Excel2007

    Java poi读取,写入Excel2007 相关阅读:poi读写Excel2003:http://www.cnblogs.com/gavinYang/p/3576739.htmljxl读写excel ...

  7. java 使用poi读取word文档存入数据库

    使用的poi jar包需要自己下载 读取的word文档中含有多个图片,所以分为两个部分,一个部分读取各个表格中内容,一个是将所有图片截取出来: /** * 遍历段落内容 * docxReadPath ...

  8. Java POI 解析word文档

    实现步骤: 1.poi实现word转html 2.模型化解析html 3.html转Map数组 Map数组(数组的操作处理不做说明) 1.导jar包. 2.代码实现 package com.web.o ...

  9. poi读取word的内容

    pache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. 1.读取word 2003及word 2007需要的 ...

  10. java中读取word文档里的内容

    package com.cn.peitest.excel.word; import java.io.FileInputStream; import java.io.FileOutputStream; ...

随机推荐

  1. 如何平稳地从nacos迁移到r-nacos?

    1. 引言 很多同学了解r-nacos特性后最开始只将r-nacos用于开发测试环境. 经过一段时间的使用后,部分同学有打算生成环境也从nacos迁移到r-nacos. 一些之前使用nacos服务的同 ...

  2. idea使用git管理项目(Mac版)

    1.本地安装git mac版 breaw install git 查看是否安装成功 git --version 这样就成功了,一般是自带的有 windows版 https://www.cnblogs. ...

  3. docker 容器迁移到其他机器

    docker 容器迁移到其他机器思路为:容器转为镜像,再保存为镜像文件,迁移到其他机器后导入为镜像 1.commit:将容器转镜像 # docker commit {container_id} {镜像 ...

  4. 浅谈 golang 代码规范, 性能优化和需要注意的坑

    浅谈 golang 代码规范, 性能优化和需要注意的坑 编码规范 [强制] 声明slice 申明 slice 最好使用 var t []int 而不是使用 t := make([]int, 0) 因为 ...

  5. Maven入门(idea)

    1.Maven是什么? Maven是一个跨平台的项目管理工具(对jar包进行统一管理). 1.1. Maven主要内容如下: 项目对象模型 项目生命周期 依赖管理系统 1.2. 使用Maven的好处: ...

  6. SourceGenerator 生成db to class代码优化结果记录

    优化 上一次实验 代码写的较为随意,本次穷尽所学,优化了一把, 不过果然还是没 比过 Dapper aot, 虽然没使用 Interceptor, 但理论上其优化不该有这么大差距 知识差距不少呀,都看 ...

  7. 基于 TrueLicense 项目证书生成

    一.创建公钥私钥 1.首先要用 KeyTool 工具来生成私匙库:(-alias别名 -validity 3650 表示10年有效,这个时间不是License的过期时间) keytool -genke ...

  8. 查看并添加python中库的搜索路径

    根据前文  pip install --user 使用方法和注意事项--python中安装module库到用户packages路径中 我们知道python中除了自身的全局module lib路径以外还 ...

  9. vscode中设置Python解释器

    以前在设置vscode中的Python解释器时都是采用图形化选择的方式来进行的,但是不知怎么的最近这个vscode在手动选择解释器时会出现时而好用时而不好用的情况,因此这里又给出了一种通过设置work ...

  10. P2P下载为什么不流行了——在线视频与P2P下载的一些比较

    平时习惯性发呆,这两天发呆想到了这么一个问题,那就是"P2P下载为什么不流行了--在线视频与P2P下载的比较".想到这个问题其实还是与自己的一些个人经历有关,在14年前读大学的时候 ...