Apache POI: How to set size of a PowerPoint document? - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

Apache POI: How to set size of a PowerPoint document?

Share This

In this tutorial we will discuss how to set page size of a Powerpoint document.

Dependencies

You can download the dependency files from here.

After downloading the libraries, you have to add them in JAVA_PATH. Alternatively, you can create an Eclipse project and add them in the project as library. You are being suggested to add the libraries as internal library instead of external library.

If you are not familier with library linking, follow these steps.

Create a directory, lib, in your project. Paste the jars in lib directory. Right click on project, select Properties, go to Java Build Path, and click on Add Jars and browse lib directory you have created. It's done!

Source Code

package com.t4b.demo.poi; import java.awt.Dimension; import org.apache.poi.xslf.usermodel.XMLSlideShow; public class PowerpointPageSizeDemo { public static void main(String[] args) { try { XMLSlideShow xmlSlideShow = new XMLSlideShow(); Dimension dimension = xmlSlideShow.getPageSize(); int width = dimension.width; int height = dimension.height; System.out.println("Width: " + width); System.out.println("Height: " + height); xmlSlideShow.setPageSize(new java.awt.Dimension(1024, 768)); java.awt.Dimension newpgsize = xmlSlideShow.getPageSize(); System.out.println("After resize!"); System.out.println("Width: " + newpgsize.width); System.out.println("Height: " + newpgsize.height); xmlSlideShow.close(); } catch (Exception e) { System.out.println(e); } } }










Happy Exploring!

No comments:

Post a Comment