个性化阅读
专注于IT技术分析

apache poi powerpoint页面大小

本文概述

我们可以获取并设置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);
		 }
	}
}

输出:

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
赞(0)
未经允许不得转载:srcmini » apache poi powerpoint页面大小

评论 抢沙发

评论前必须登录!