Apache POI PPT 获取和设置页面大小

我们可以获取和设置PPT页面的页面大小。要获得页面大小调用 getPageSize()方法 ,设置页面大小则使用 setPageSize()方法。让我们看一个例子。

Apache POI PPT 获取页面大小示例

package com.yiidian;

import org.apache.poi.xslf.usermodel.XMLSlideShow;

import java.io.FileInputStream;

public class SlideSizeExample {
    public static void main(String[] args) {  
        try(XMLSlideShow ppt = new XMLSlideShow(new FileInputStream("yiidian.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 PPT设置页面大小示例

package com.yiidian;

import org.apache.poi.xslf.usermodel.XMLSlideShow;

import java.io.FileInputStream;

public class SlideSizeExample {
    public static void main(String[] args) {  
        try(XMLSlideShow ppt = new XMLSlideShow(new FileInputStream("yiidian.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

Slide size after setting new size.
width: 1024
height: 768

 

热门文章

优秀文章