当前位置: 首页 > news >正文

企业网站建设对企业客户的意义轮网站开发的重要性

企业网站建设对企业客户的意义,轮网站开发的重要性,酒店网站制作策划,做网站做什么公司好本文介绍如何使用Apache POI识别PPT中的图片和文字,获取图片的数据、大小、尺寸、坐标,以及获取文字的字体、大小、颜色、坐标。 官方文档:https://poi.apache.org/components/slideshow/xslf-cookbook.html 官方文档和网上的资料介绍的很少…

本文介绍如何使用Apache POI识别PPT中的图片和文字,获取图片的数据、大小、尺寸、坐标,以及获取文字的字体、大小、颜色、坐标。

官方文档:https://poi.apache.org/components/slideshow/xslf-cookbook.html

官方文档和网上的资料介绍的很少,很多元素,需要一点点尝试才能获取到。

注意:本篇文章针对.pptx结尾的PPT文件

引入依赖:

 		<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>5.0.0</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.0.0</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-scratchpad</artifactId><version>5.0.0</version></dependency>

核心代码:

	private static final String FILE_PATH = "/Temp/PPT/test.pptx";private static final String OUTPUT_PATH = "/Temp/PPT/output/";private static final String RGBA_TEMPLATE = "rgba(%d,%d,%d,1)";public static void main(String[] args) {analysisPpt(FILE_PATH);}public static void analysisPpt(String filePath) {try {InputStream input = new FileInputStream(filePath);XMLSlideShow xss = new XMLSlideShow(input);//getSlides(); 返回幻灯片中找到的所有普通幻灯片List<XSLFSlide> xslfSlideList = xss.getSlides();for (XSLFSlide xslfSlide : xslfSlideList) {//HSLFShape表示工作表中包含的所有形状(幻灯片或注释)List<XSLFShape> shapes = xslfSlide.getShapes();handleShapes(shapes);}} catch (Exception e) {e.printStackTrace();}}private static void handleShapes(final List<XSLFShape> shapes) throws Exception {for (XSLFShape shape : shapes) {if (shape instanceof XSLFGroupShape) {XSLFGroupShape groupShape = ((XSLFGroupShape) shape);// 对XSLFGroupShape进行递归处理handleShapes(groupShape.getShapes());} else if (shape instanceof XSLFTextShape) {XSLFTextShape xslfTextShape = ((XSLFTextShape) shape);List<XSLFTextParagraph> textParagraphs = xslfTextShape.getTextParagraphs();XSLFTextRun textRun = textParagraphs.get(0).getTextRuns().get(0);Rectangle2D anchor = xslfTextShape.getAnchor();PaintStyle fontColor = textRun.getFontColor();Color color = null;if (Objects.nonNull(fontColor)) {if (fontColor instanceof PaintStyle.SolidPaint) {PaintStyle.SolidPaint solidPaint = (PaintStyle.SolidPaint) fontColor;color = solidPaint.getSolidColor().getColor();} else if (fontColor instanceof XSLFTexturePaint) {// 一些大标题是该类型,暂无法获取大标题文字颜色XSLFTexturePaint texturePaint = (XSLFTexturePaint) fontColor;System.out.println("todo: XSLFTexturePaint ");} else {System.out.println("not match: " + fontColor.getClass());}}String fill = "";if (Objects.nonNull(color)) {fill = String.format(RGBA_TEMPLATE, color.getRed(), color.getGreen(), color.getBlue());}System.out.printf("[text]: %s \n[font]: %s [size]: %s [x,y]: (%s,%s) [color]: %s \n", xslfTextShape.getText(),textRun.getFontFamily(), textRun.getFontSize(), anchor.getX(), anchor.getY(), fill);System.out.println("----------------------------");} else if (shape instanceof XSLFPictureShape) {XSLFPictureShape xslfPictureShape = ((XSLFPictureShape) shape);XSLFPictureData pictureData = xslfPictureShape.getPictureData();// 图片数据byte[] data = pictureData.getData();savePicture(data, pictureData.getFileName());Dimension dimensionInPixels = pictureData.getImageDimensionInPixels();Rectangle2D anchor = xslfPictureShape.getAnchor();System.out.printf("[picture name]: %s: [size]: %s * %s [X,Y]: (%s,%s) \n", pictureData.getFileName(), dimensionInPixels.getWidth(),dimensionInPixels.getHeight(), anchor.getX(), anchor.getY());} else {System.out.println("unknown shape:" + shape.getClass());}}}private static void savePicture(final byte[] data, final String fileName) throws IOException {FileOutputStream out = new FileOutputStream(OUTPUT_PATH + fileName);out.write(data);out.close();}
http://www.yayakq.cn/news/838149/

相关文章:

  • 东莞工业品网站建设私密浏览器看片大全免费直播
  • 网站域名解析错误怎么办网站怎样设计网址大全
  • 佛山移动网站设计佛山网站建设与设计公司
  • 建企业门户网站横沥东莞网站建设
  • 手机网站是什么seo排名课程咨询电话
  • 做App和网站 聚马报名网站制作
  • 西安煤炭建设监理中心网站外贸企业建网站
  • wordpress学校站模板网站建设怎么样找客户快
  • 建设银行面试通知网站画册排版设计模板
  • 手机网站开发技术路线杭州网页设计工作室
  • 刷网站排名 优帮云企业网站备案 淘宝客
  • 自己建设影视网站手机客户端app下载安装
  • jsp是否可以做网站网页设计基础考试题库及答案
  • 无障碍网站建设标准做网站合同模板
  • 怎样在工商局网站上做网登168义乌加工网
  • 厦门网站建设是什么dede网站开发步骤
  • 广州南沙网站建设商铺装修找谁
  • 藁城住房和城乡建设局网站泵网站建设
  • 关注济南网站建设企业网站建设因素分析
  • 济南做外贸的网站公司网站及微信建设是否涉及知识产权
  • 返利网站开发seo对网站的作用
  • 建设好网站能赚到钱吗?软件开发文档总结
  • 苏州市规划建设局网站上传了网站程序后
  • 四川成都网站建设网页制作设计作品
  • html5网站开发需要框架吗公司宣传册排版
  • 无锡那家网络公司做网站好企业网站建设项目
  • 智能锁网站建设关键词本网站维护升级
  • 池州网站建设全包网站链接提交
  • 教育培训类网站开发wordpress 权限 分类
  • 网站建设方案doc软件项目管理的概念