Java解析PPT获取文本和图片
需要引用的包
poi-ooxml-4.1.2.jar
import org.apache.poi.xslf.usermodel.*;
主要实现方法
public static FileTextVo getPPTXText(String fileName, InputStream inputStream) throws Exception {try {SlideShow slideShow = null;if ( fileName.toLowerCase().endsWith(".pptx")) {slideShow= new XMLSlideShow(inputStream);}else{slideShow= new HSLFSlideShow(inputStream);}List<XSLFSlide> slides = slideShow.getSlides();StringBuffer content = new StringBuffer();for (Object slide : slides) {if(slide instanceof XSLFSlide) {List<XSLFShape> shapes = ((XSLFSlide)slide).getShapes();for (XSLFShape sh : shapes) {getShapesTxt(sh, content);}}if(slide instanceof HSLFSlide) {List<HSLFShape> shapes = ((HSLFSlide)slide).getShapes();for (HSLFShape sh : shapes) {getShapesTxt(sh, content);}}}//获取图片信息List pictureDateList = slideShow.getPictureData();if (!ObjectUtils.isEmpty(pictureDateList)) {for (int i = 0; i < pictureDateList.size(); i++) {if (fileName.toLowerCase().endsWith(".pptx")) {XSLFPictureData picture = (XSLFPictureData) pictureDateList.get(i);InputStream sbs = new ByteArrayInputStream(picture.getData());} else {HSLFPictureData picture = (HSLFPictureData) pictureDateList.get(i);InputStream sbs = new ByteArrayInputStream(picture.getData());}}}} finally {if (inputStream != null) {// 关闭输出流inputStream.close();}}return vo;}//获取文本信息private static void getShapesTxt(XSLFShape shape,StringBuffer content) {if (shape instanceof XSLFTextShape) {XSLFTextShape txtshape = (XSLFTextShape) shape;String sentence = txtshape.getText();content.append(sentence);
// System.out.println(txtshape.getText());} else if (shape instanceof XSLFAutoShape) {XSLFAutoShape autoShape = (XSLFAutoShape) shape;content.append(autoShape.getText());} else if (shape instanceof XSLFFreeformShape) {XSLFFreeformShape shape2 = (XSLFFreeformShape) shape;content.append(shape2.getText());} else if (shape instanceof XSLFConnectorShape) {XSLFConnectorShape shape2 = (XSLFConnectorShape) shape;content.append(shape2.getShapeName());} else if (shape instanceof XSLFPictureShape) {XSLFPictureShape shape2 = (XSLFPictureShape) shape;content.append(shape2.getShapeName());} else if (shape instanceof XSLFGroupShape) {//如果是组合类型,继续下钻直到取到文本XSLFGroupShape shape2 = (XSLFGroupShape) shape;for (XSLFShape xslfShape : shape2) {getShapesTxt(xslfShape,content);}} else if (shape instanceof XSLFSimpleShape) {XSLFSimpleShape shape2 = (XSLFSimpleShape) shape;content.append(shape2.getShapeName());}}
Java解析PPT获取文本和图片相关推荐
- Java解析Excel 获取文本和图片信息
1.引入jar package org.apache.poi.hssf.usermodel; package org.apache.poi.ooxml; package org.apache.poi. ...
- java解析pdf获取pdf中内容信息
java解析pdf获取pdf中内容信息 今日项目中需要将pdf中的数据获取到进行校验数据,于是前往百度翻来覆去找到以下几种办法,做个笔记,方便日后查询. 废话不多说,我要直接上代码装逼了 第一种 使用 ...
- Java Word中的文本、图片替换功能
Word中的替换功能以查找指定文本然后替换为新的文本,可单个替换或全部替换.以下将要介绍的内容,除常见的以文本替换文本外,还将介绍使用不同对象进行替换的方法,具体可包括: 1. 指定字符串内容替换文本 ...
- Java解析excel表格中的图片的方式
我们要用java解析首先得在项目中引入解析excel的相关包,我们这里使用的是apache的poi-3.12.jar来做开发. 首先获取excel文件,获取文件的方式这里就不细说了,获取到文件后,将文 ...
- java 解析ppt动画_姜子牙口碑崩盘?我们为它做了这份炸裂的PPT!(领取源文件)...
不知道大家是否记得,去年的暑期档,一部初始让人并不看好的国漫「哪吒:魔童降世」,刷爆了整个电影圈,最终以50亿的票房成绩拿下中国影史第二的宝座,口碑票房双丰收.在片尾的彩蛋,彩条屋"封神宇宙 ...
- java 解析ppt动画_上映17天,姜子牙口碑一路狂跌,但这份PPT让它又火了!
关注我?发送「找素材」免费领 10+ 模板.图库网站! 小叶子们好,前不久我们拆解过<姜子牙>这部电影的海报设计技巧,很多小伙伴表示画面太美没看过瘾. 好,我们懂了. 前段时间,粒子.二木 ...
- java解析wrod带公式带图片
直接上代码 word里面添加的图片不能浮动,这个很重要 package com.topic.util;import com.alibaba.fastjson.JSONObject; import co ...
- java解析XML获取城市代码
运行前先导入dom4j架包,由于我们公司用的代理服务器所以下面我设置了代理ip,不需要的可直接忽略 package com.chengshidaima.tools;import java.io.Buf ...
- java 解析excel获取单元格内容封装方法(兼容2003和2007)
支持xls2003及xlsx2007导入excel //导入excel接口 @RequestMapping(params = "importDecMainCode", method ...
最新文章
- 转:java中数组与List相互转换的方法
- 服务器相关命令整理[不断更新ing]
- php pdo操作数据库
- 《剑指offer》-斐波那契数列
- swoole php input,介绍swoole异步群发模板消息
- python汉字拼音查询_python获取一组汉字拼音首字母的方法
- [转载] 【python】Python中*args和**kwargs的区别(在Python中如何使用可变长参数列表)
- Google分析用户页面滚动深度分析jQuery插件 - jQuery Scroll Depth
- sort()函数关于结构内容要怎么写
- MATLAB的一个FFT程序
- Unity EasyAR图像跟踪
- Knowledge 7一阶谓词逻辑-Generalized Modus Ponens规则
- 联想小新固态硬盘安装Win7或者win10过程
- 编程数学读书笔记 -- 第二章逻辑
- 养生秘方,专治各种小毛病,千万别弄丢了!
- Latex-加通讯作者的小信封标记
- 单词接龙acwing
- python邮件发送
- NMEA-GPS协议
- Python中办公软件(创建excel)