当前位置: 首页 > 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/752942/

相关文章:

  • 好游快游app官方网站下载用书籍上的文章做网站SEO
  • 官方网站建设计划苏州设计
  • 口碑好的南昌网站建设免费做网站哪家好
  • 茂名网站制作网上申报办税系统
  • 网站建设的知识产权归属wordpress怎么显示文章时间
  • 广州网站建设服务公司wordpress 模板 源码
  • 签合网站是哪个好长春 网络公司
  • 学校门户网站建设工作汇报淘客网站是怎么做的
  • 烟台城乡住房建设厅网站做好网站建设总结
  • 个人名义做网站郑州电力高等专科学校录取分数线
  • 山东省住房与建设厅网站口碑好网站建设价格低
  • 购物网站优化方案上海陆海建设集团网站
  • 网站推广公司什么是网络营销和技巧
  • 河南网络科技网站建设企业如何网络推广
  • 哈尔滨速成网站建设网站后台为什么传不上图片
  • 如何做导购网站橘子皮主题wordpress
  • 网站的网站建设公司京东这样的网站怎么做
  • 赤峰建设局网站自媒体运营主要做什么
  • 免费网站制作范例西安seo关键词排名
  • wordpress多站点注册页建设工程信息网官网入口查询
  • 做好的网站怎么发布网站搭建实训报告
  • 网上做网站赚钱吗用qq空间做网站
  • 北京商城网站设计报价wordpress前台浏览量插件
  • 企业建设营销网站的基本步骤有哪些手机优化怎么关闭
  • 用邮箱做网站做mip网站需要多钱
  • 怎么做集团网站网络购物商城网站建设
  • 以前老网站兼职做设计什么网站好
  • p2p网站建设要点网站建设和续费
  • wix做的网站 网址是什么网页制作与网站建设技术大全 pdf
  • 上海网站制作服务我要外包网站