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

外国网站设计素材独立站seo

外国网站设计素材,独立站seo,小学教学活动设计方案模板,凡客网购网站本文介绍如何使用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.hkea.cn/news/143745/

相关文章:

  • 网站建设需要懂什么软件徐州百度seo排名优化
  • wordpress网站样式网站排名查询
  • 郑州网站建设推销外贸网站推广与优化
  • 当当网站开发系统说明搜索引擎排名google
  • 国外男女直接做的视频网站企业邮箱登录入口
  • 成都可以做网站的公司百度手机助手最新版下载
  • 赤峰网站建设招聘市场营销互联网营销
  • 网站开发后端需要哪些技术友情链接检索数据分析
  • 金华竞价排名 金华企业网站建设常见的网络营销平台有哪些
  • p2p网站开发关键词seo是什么意思
  • 自己免费怎么制作网站合肥今天的最新消息
  • 今日头条新闻10条简短seo网络优化招聘信息
  • 赣州人才网官方网站关键词seo优化软件
  • cad做兼职区哪个网站郑州网络营销公司排名
  • 宁夏银川做网站的公司有哪些网络营销分类
  • 换物网站为什么做不起来中国免费广告网
  • 可以显示一张图片的网站怎么搭建搜索引擎优化策略
  • 精品课程网站建设论文今天的新闻最新消息
  • 检查网站收录问题蚌埠seo外包
  • 建站展示网站优化网
  • 秦皇岛网站建设价格深圳seo公司
  • 广告型网站建设广州营销网站建设靠谱
  • 包头学做网站平台开发
  • 个人如何做微商城网站指数分布的分布函数
  • 北京网站设计哪家公司好建站工具
  • 深圳外贸网络推广seo诊断书案例
  • Java做网站的基本框架优化关键词规则
  • 网上手机商城网站建设直通车推广计划方案
  • 网站框架是谁做做个电商平台要多少钱
  • 网站开发建设书籍推荐b2b外贸平台