apache poi powerpoint页面大小

本文概述

  • Apache POI页面大小示例
  • Apache POI设置页面大小示例
我们可以获取并设置PowerPoint页面的页面大小。要获取页面大小,请使用getPageSize()方法,而要设置大小,请使用setPageSize()方法。
检索到的页面大小返回以点表示的坐标。让我们来看一个例子。
Apache POI页面大小示例
package poiexample; import java.io.FileInputStream; import org.apache.poi.xslf.usermodel.XMLSlideShow; public class SlideSizeExample { public static void main(String[] args) { try(XMLSlideShow ppt = new XMLSlideShow(new FileInputStream("srcmini.pptx"))){ java.awt.Dimension pgsize = ppt.getPageSize(); int width = pgsize.width; //slide width in points int height = pgsize.height; //slide height in points System.out.println("width: "+width); System.out.println("height: "+ height); }catch(Exception e) { System.out.println(e); } } }

【apache poi powerpoint页面大小】输出:
width: 720 height: 540

让我们来看一个设置页面大小的示例。
Apache POI设置页面大小示例
package poiexample; import java.io.FileInputStream; import org.apache.poi.xslf.usermodel.XMLSlideShow; public class SlideSizeExample { public static void main(String[] args) { try(XMLSlideShow ppt = new XMLSlideShow(new FileInputStream("srcmini.pptx"))){ java.awt.Dimension pgsize = ppt.getPageSize(); int width= pgsize.width; //slide width in points int height = pgsize.height; //slide height in points System.out.println("width: "+width); System.out.println("height: "+ height); ppt.setPageSize(new java.awt.Dimension(1024, 768)); java.awt.Dimension newpgsize = ppt.getPageSize(); System.out.println("\nSlide size after setting new size."); System.out.println("width: "+newpgsize.width); System.out.println("height: "+ newpgsize.height); }catch(Exception e) { System.out.println(e); } } }

输出:
width: 720 height: 540

设置新尺寸后的幻灯片尺寸。
width: 1024 height: 768

    推荐阅读