Document Operation (11)
Presenting information in a logical sequence is vital for an effective PowerPoint presentation. Reordering slides in a PowerPoint document gives you the flexibility to fine-tune your presentation and ensure that it delivers your message with maximum impact. By organizing your slides strategically, you can create a dynamic and engaging presentation experience.
In this article, you will learn how to reorder slides in a PowerPoint document in Java using the Spire.Presentation for Java library.
Install Spire.Presentation for Java
First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation</artifactId>
<version>10.11.4</version>
</dependency>
</dependencies>
Reorder Slides in a PowerPoint Document in Java
To rearrange the slides in a PowerPoint presentation, you need to create two presentation objects. One object will be used to load the original document while the other will be used to create a new document. By copying the slides from the original document to the new document in the desired order, you can effectively rearrange the slides.
The following are the steps to rearrange slides in a PowerPoint document using Java.
- Create a Presentationobject.
- Load a PowerPoint document using Presentation.loadFromFile() method.
- Specify the slide order within an array.
- Create another Presentation object for creating a new presentation.
- Add the slides from the original document to the new presentation in the specified order using Presentation.getSlides().append() method.
- Save the new presentation to a PPTX file using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
public class ReorderSlides {
public static void main(String[] args) throws Exception {
// Create a Presentation object
Presentation presentation = new Presentation();
// Load a PowerPoint file
presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\input.pptx");
// Specify the new slide order within an array
int[] newSlideOrder = new int[] { 3, 4, 1, 2 };
// Create another Presentation object
Presentation new_presentation = new Presentation();
// Remove the default slide
new_presentation.getSlides().removeAt(0);
// Iterate through the array
for (int i = 0; i < newSlideOrder.length; i++)
{
// Add the slides from the original PowerPoint file to the new PowerPoint document in the new order
new_presentation.getSlides().append(presentation.getSlides().get(newSlideOrder[i] - 1));
}
// Save the new presentation to file
new_presentation.saveToFile("output/NewOrder.pptx", FileFormat.PPTX_2019);
// Dispose resources
presentation.dispose();
new_presentation.dispose();
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
The background of a PowerPoint presentation sets the tone and mood of the presentation and can greatly enhance the aesthetic and impact of the slides. There are five types of backgrounds available in PowerPoint presentations, solid color backgrounds, gradient backgrounds, picture backgrounds, texture backgrounds, and patterned backgrounds. They each apply to different usage scenarios. For example, a professional business presentation may benefit from a clean and simple solid color background, while a creative presentation may use inspiring and interesting picture backgrounds to capture the audience's attention. This article is going to show how to set backgrounds for PowerPoint presentations through Java programs using Spire.Presentation for Java.
- Set a Solid Color Background for a PowerPoint Presentation
- Set a Gradient Background for a PowerPoint Presentation
- Set a Picture Background for a PowerPoint Presentation
- Set a Texture Background for a PowerPoint Presentation
- Set a Pattern Background for a PowerPoint Presentation
Install Spire.Presentation for Java
First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation</artifactId>
<version>10.11.4</version>
</dependency>
</dependencies>
Set a Solid Color Background for a PowerPoint Presentation
Before customizing the background, it is necessary to use the SlideBackground.setType(BackgroundType.CUSTOM) method to allow the customization of the background. Then, the background type can be set to solid color background using the SlideBackground.getFill().setFillType(FillFormatType.SOLID) method, and the color can be set using the FillFormat.getSolidColor().setColor() method.
The detailed steps are as follows:
- Create an object of Presentation class.
- Load a PowerPoint presentation using Presentation.loadFromFile() method.
- Get the first slide using Presentation.getSlides().get() method.
- Get the background of the slide using ISlide.getSlideBackground() method.
- Set the background type to custom background to enable the customization of the background using SlideBackground.setType(BackgroundType.CUSTOM) method.
- Set the fill type of the background to solid color using SlideBackground.getFill().setFillType(FillFormatType.SOLID) method.
- Customize the background color using FillFormat.getSolidColor().setColor() method.
- Save the presentation using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideBackground;
import com.spire.presentation.drawing.BackgroundType;
import com.spire.presentation.drawing.FillFormat;
import com.spire.presentation.drawing.FillFormatType;
import org.w3c.dom.css.RGBColor;
import java.awt.*;
public class SolidColor {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation ppt = new Presentation();
//Load a PowerPoint presentation
ppt.loadFromFile("Sample.pptx");
//Get the first slide
ISlide slide = ppt.getSlides().get(0);
//Get the background
SlideBackground background = slide.getSlideBackground();
//Set the background type to custom
background.setType(BackgroundType.CUSTOM);
//Set the background fill type to solid color
background.getFill().setFillType(FillFormatType.SOLID);
//Set the background color
FillFormat fillFormat = background.getFill();
fillFormat.getSolidColor().setColor(new Color(199, 213, 237));
//Save the presentation
ppt.saveToFile("SolidColorBackground.pptx", FileFormat.AUTO);
}
}

Set a Gradient Background for a PowerPoint Presentation
Gradient background can be set by setting the background type to Gradient Background and then setting the gradient type, color, and angle. The detailed steps are as follows:
- Create an object of Presentation class.
- Load a PowerPoint presentation using Presentation.loadFromFile() method.
- Get the first slide using Presentation.getSlides().get() method.
- Get the background of the slide using ISlide.getSlideBackground() method.
- Set the background type to custom background to enable the customization of the background using SlideBackground.setType(BackgroundType.CUSTOM) method.
- Set the fill type of the background to gradient using SlideBackground.getFill().setFillType(FillFormatType.GRADIENT) method.
- Set the gradient type to linear gradient using GradientFillFormat.setGradientShape(GradientShapeType.LINEAR) method.
- Add the gradient stops and set the gradient colors using GradientFillFormat.getGradientStops().append() method.
- Set the angle of the linear gradient using GradientFillFormat.getLinearGradientFill().setAngle() method.
- Save the presentation using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideBackground;
import com.spire.presentation.drawing.*;
import java.awt.*;
public class Gradient {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation ppt = new Presentation();
//Load a PowerPoint presentation
ppt.loadFromFile("Sample.pptx");
//Get the first slide
ISlide slide = ppt.getSlides().get(0);
//Get the background
SlideBackground background = slide.getSlideBackground();
//Set the background type to custom
background.setType(BackgroundType.CUSTOM);
//Set the background fill type to gradient color
background.getFill().setFillType(FillFormatType.GRADIENT);
//Set the gradient type to linear
GradientFillFormat gradient = background.getFill().getGradient();
gradient.setGradientShape(GradientShapeType.LINEAR);
//Add gradient stops and set the colors
gradient.getGradientStops().append(0f, new Color(230, 255, 255));
gradient.getGradientStops().append(0.5f, new Color(255, 255, 255));
gradient.getGradientStops().append(1f, new Color(199, 213, 237));
//Set the angle of the linear gradient
gradient.getLinearGradientFill().setAngle(90);
//Save the presentation
ppt.saveToFile("GradientBackground.pptx", FileFormat.AUTO);
}
}

Set a Picture Background for a PowerPoint Presentation
To set the picture background, set the background type to picture, set the picture fill type to stretch fill, and then set the background image. The detailed steps are as follows:
- Create an object of Presentation class.
- Load a PowerPoint presentation using Presentation.loadFromFile() method.
- Load a picture using Presentation.getImages().append() method.
- Get the first slide using Presentation.getSlides().get() method.
- Get the background of the slide using ISlide.getSlideBackground() method.
- Set the background type to custom background to enable the customization of the background using SlideBackground.setType(BackgroundType.CUSTOM) method.
- Set the fill type of the background to picture using SlideBackground.getFill().setFillType(FillFormatType.PICTURE) method.
- Set the picture fill type to stretch fill using PictureFillFormat.setFillType(PictureFillType.STRETCH) method.
- Set the transparency of the background using PictureFillFormat.getPicture().setTransparency() method.
- Set the background image using PictureFillFormat.getPicture().setEmbedImage() method.
- Save the presentation using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideBackground;
import com.spire.presentation.drawing.*;
import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
public class Picture {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation ppt = new Presentation();
//Load a PowerPoint presentation
ppt.loadFromFile("Sample.pptx");
//Load a picture
IImageData image = ppt.getImages().append(ImageIO.read(new File("background.jpg")));
//Get the first slide
ISlide slide = ppt.getSlides().get(0);
//Get the background
SlideBackground background = slide.getSlideBackground();
//Set the background type to custom
background.setType(BackgroundType.CUSTOM);
//Set the background fill type to picture
background.getFill().setFillType(FillFormatType.PICTURE);
//Set the picture fill type to stretch
PictureFillFormat pictureFillFormat = background.getFill().getPictureFill();
pictureFillFormat.setFillType(PictureFillType.STRETCH);
//Set the transparency of the background
pictureFillFormat.getPicture().setTransparency(50);
//Set the background picture
pictureFillFormat.getPicture().setEmbedImage(image);
//Save the presentation
ppt.saveToFile("PictureBackground.pptx", FileFormat.AUTO);
}
}

Set a Texture Background for a PowerPoint Presentation
Setting a texture background is similar to setting a picture background. The difference is that the image fill type needs to be changed to a tiled fill and the texture alignment needs to be set. The detailed steps are as follows:
- Create an object of Presentation class.
- Load a PowerPoint presentation using Presentation.loadFromFile() method.
- Load the texture using Presentation.getImages().append() method.
- Get the first slide using Presentation.getSlides().get() method.
- Get the background of the slide using ISlide.getSlideBackground() method.
- Set the background type to custom background to enable the customization of the background using SlideBackground.setType(BackgroundType.CUSTOM) method.
- Set the fill type of the background to picture using SlideBackground.getFill().setFillType(FillFormatType.PICTURE) method.
- Set the picture fill type to tile fill using PictureFillFormat.setFillType(PictureFillType.TILE) method.
- Set the transparency of the background using PictureFillFormat.getPicture().setTransparency() method.
- Set the background texture using PictureFillFormat.getPicture().setEmbedImage() method.
- Save the presentation using Presentation.saveToFile() method.
- Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import javax.imageio.ImageIO;
import java.io.File;
public class Texture {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation ppt = new Presentation();
//Load a PowerPoint presentation
ppt.loadFromFile("Sample.pptx");
//Load the texture
IImageData image = ppt.getImages().append(ImageIO.read(new File("texture.png")));
//Get the first slide
ISlide slide = ppt.getSlides().get(0);
//Get the background
SlideBackground background = slide.getSlideBackground();
//Set the background type to custom
background.setType(BackgroundType.CUSTOM);
//Set the background fill type to picture
background.getFill().setFillType(FillFormatType.PICTURE);
//Set the picture fill type to tile
PictureFillFormat pictureFillFormat = background.getFill().getPictureFill();
pictureFillFormat.setFillType(PictureFillType.TILE);
//Set the texture alignment
pictureFillFormat.setAlignment(RectangleAlignment.TOP_LEFT);
//Set the transparency of the background
pictureFillFormat.getPicture().setTransparency(50);
//Set the background texture
pictureFillFormat.getPicture().setEmbedImage(image);
//Save the presentation
ppt.saveToFile("TextureBackground.pptx", FileFormat.AUTO);
}
}

Set a Pattern Background for a PowerPoint Presentation
In adding a pattern background, it is necessary to set the type of pattern as well as the foreground and background colors of the pattern. The detailed steps are as follows:
- Create an object of Presentation class.
- Load a PowerPoint presentation using Presentation.loadFromFile() method.
- Get the first slide using Presentation.getSlides().get() method.
- Get the background of the slide using ISlide.getSlideBackground() method.
- Set the background type to custom background to enable the customization of the background using SlideBackground.setType(BackgroundType.CUSTOM) method.
- Set the fill type of the background to pattern using SlideBackground.getFill().setFillType(FillFormatType.PATTERN) method.
- Set the pattern type using PatternFillFormat.setPatternType() method.
- Set the foreground color of the pattern using PatternFillFormat.getForegroundColor().setColor() method.
- Set the background color of the pattern using PatternFillFormat.getBackgroundColor().setColor() method.
- Save the presentation using Presentation.saveToFile() method.
- Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
public class Pattern {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation ppt = new Presentation();
//Load a PowerPoint presentation
ppt.loadFromFile("Sample.pptx");
//Get the first slide
ISlide slide = ppt.getSlides().get(0);
//Get the background
SlideBackground background = slide.getSlideBackground();
//Set the background type to custom
background.setType(BackgroundType.CUSTOM);
//Set the background fill type to pattern
background.getFill().setFillType(FillFormatType.PATTERN);
//Set the pattern type
PatternFillFormat patternFillFormat = background.getFill().getPattern();
patternFillFormat.setPatternType(PatternFillType.DOTTED_GRID);
//Set the foreground color of the pattern
patternFillFormat.getForegroundColor().setColor(new Color(230, 255, 255));
//Set the background color of the pattern
patternFillFormat.getBackgroundColor().setColor(new Color(199, 213, 237));
//Save the presentation
ppt.saveToFile("PatternBackground.pptx", FileFormat.AUTO);
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
The slide size is one of the important aspects of the visual design of PowerPoint presentations. It influences the aspect ratio and dimensions of the presentation and can have a significant impact on the overall appearance and atmosphere of the presentation. If the default slide size does not meet the visual design requirements or does not match the size of the screen showing the presentation, it is necessary to change the size of the slides to another preset size or customize a slide size. This article will demonstrate how to change the slide size of PowerPoint presentations through Java programs using Spire.Presentation for Java.
Install Spire.Presentation for Java
First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation</artifactId>
<version>10.11.4</version>
</dependency>
</dependencies>
Change the Slide Size to a Preset Size
Spire.Presentation for Java provides the Presentation.getSlideSize().setType() method to change the slide size to a preset size. The detailed steps are as follows:
- Create an object of Presentation class.
- Load a PowerPoint presentation using Presentation.loadFromFile() method.
- Change the slide type of the presentation using Presentation.getSlideSize().setType() method.
- Save the presentation using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideSizeType;
public class changeSlideSizePreset {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation pt = new Presentation();
//Load a presentation file
pt.loadFromFile("Sample.pptx");
//Change the slide size of the presentation to A4
pt.getSlideSize().setType(SlideSizeType.A4);
//Save the presentation file
pt.saveToFile("A4Size.pptx", FileFormat.AUTO);
pt.dispose();
}
}

Change the Slide Size to a Custom Size
Customizing the size of slides requires changing the slide size type to custom. After that, the Presentation.getSlideSize().setSize() method can be used to customize the slide size. The detailed steps are as follows:
- Create an object of Presentation class.
- Load a PowerPoint presentation using Presentation.loadFromFile() method.
- Change the slide size type to custom using Presentation.getSlideSize().setType() method.
- Customize the slide size using Presentation.getSlideSize().setSize() method.
- Save the presentation using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideSize;
import com.spire.presentation.SlideSizeType;
import java.awt.*;
public class changeSlideSizeCustom {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation pt = new Presentation();
//Load a PowerPoint presentation
pt.loadFromFile("Sample.pptx");
//Change the slide size type to custom
pt.getSlideSize().setType(SlideSizeType.CUSTOM);
//Set the slide size
pt.getSlideSize().setSize(new Dimension(600, 600));
//Save the presentation file
pt.saveToFile("CustomSize.pptx", FileFormat.AUTO);
pt.dispose();
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Suppose there are two PowerPoint documents, and you want to copy a certain slide from one document to a specified location of the other. Manual copying and pasting is an option, but the quicker and more efficient way is to use Java codes for automatic operation. This article will show you how to programmatically copy slides between two different PowerPoint documents using Spire.Presentation for Java.
Install Spire.Presentation for Java
First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation</artifactId>
<version>10.11.4</version>
</dependency>
</dependencies>
Copy Slides Between Two PowerPoint Documents
The following are detailed steps to copy a slide from one PowerPoint document to a specified position or the end of the other document.
- Create a Presentation object and load one sample document using Presentation.loadFromFile() method.
- Create another Presentation object and load the other sample document using Presentation.loadFromFile() method.
- Get a specific slide of document one using Presentation.getSlides().get() method and insert its copy into the specified position of document two using Presentation.getSlides().insert() method.
- Get another specific slide of document one using Presentation.getSlides().get() method and add its copy to the end of document two using Presentation.getSlides().append() method.
- Save the document two to another file using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
public class CopySlidesBetweenPPT {
public static void main(String[] args) throws Exception {
//Create a Presentation object to load one sample document
Presentation pptOne= new Presentation();
pptOne.loadFromFile("C:\\Users\\Test1\\Desktop\\sample1.pptx");
//Create another Presentation object to load the other sample document
Presentation pptTwo = new Presentation();
pptTwo.loadFromFile("C:\\Users\\Test1\\Desktop\\sample2.pptx");
//Insert the specific slide from document one into the specified position of document two
pptTwo.getSlides().insert(0,pptOne.getSlides().get(0));
//Append the specific slide of document one to the end of document two
pptTwo.getSlides().append(pptOne.getSlides().get(3));
//Save the document two to another file
pptTwo.saveToFile("output/CopySlidesBetweenPPT.pptx", FileFormat.PPTX_2013);
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
This article demonstrates how to set and get slide title in a PowerPoint document using Spire.Presentation for Java.
Set slide title
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
public class SetSlideTitle {
public static void main(String[] args) throws Exception {
//Create a Presentation instance
Presentation ppt = new Presentation();
//Get the first slide
ISlide slide = ppt.getSlides().get(0);
//Set title for the slide
slide.setTitle("Tile Text");
//Save the result document
ppt.saveToFile("SetTitle.pptx", FileFormat.PPTX_2013);
}
}

Get slide title
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
public class GetSlideTitle {
public static void main(String[] args) throws Exception {
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a PowerPoint document
ppt.loadFromFile("SetTitle.pptx");
//Get the first slide
ISlide slide = ppt.getSlides().get(0);
//Print out the title of the slide
String tile = slide.getTitle();
System.out.println(tile);
}
}

Java: Set, Retrieve, or Delete Document Properties in PowerPoint
2023-08-10 07:54:00 Written by KoohjiDocument properties of PowerPoint presentations hold immense value in managing and organizing presentations. The information in properties, including title, author, keywords, etc., provides a concise summary, aids in categorization and searchability, and contributes to maintaining a comprehensive presentation history. However, some useless document properties need to be deleted to prevent them from affecting document management. This article is going to show how to add, retrieve, or delete document properties in PowerPoint presentations using Spire.Presentation for Java.
- Add Document Properties to a PowerPoint Presentation
- Retrieve Document Properties from a PowerPoint Presentation
- Delete Document Properties of a PowerPoint Presentation
Install Spire.Presentation for Java
First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation</artifactId>
<version>10.11.4</version>
</dependency>
</dependencies>
Add Document Properties to a PowerPoint Presentation
Spire.Presentation for Java provides a set of methods under IDocumentProperty class to enable users to set and retrieve document properties of a presentation after getting the properties using the Presentation.getDocumentProperty() method. The detailed steps for adding document properties to a PowerPoint presentation are as follows:
- Create an object of Presentation class.
- Load a presentation file using Presentation.loadFromFile() method.
- Get the document properties of the presentation using Presentation.getDocumentProperty() method.
- Set the document properties using methods under IDocumentProperty class.
- Save the presentation using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.IDocumentProperty;
import com.spire.presentation.Presentation;
public class addPresentationProperties {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation presentation = new Presentation();
//Load a PowerPoint presentation
presentation.loadFromFile("Sample.pptx");
//Get the properties of the presentation and add items
IDocumentProperty property = presentation.getDocumentProperty();
property.setTitle("Annual Business Analysis Report");
property.setSubject("Business Analysis");
property.setAuthor("Taylor");
property.setManager("John");
property.setCompany("E-iceblue");
property.setCategory("Report");
property.setKeywords("Operating Analysis; Quarterly Operating Data; Growth");
property.setComments("The report has been revised and finalized and does not require further consultation.");
//Save the presentation file
presentation.saveToFile("AddProperties.pptx", FileFormat.AUTO);
presentation.dispose();
}
}

Retrieve Document Properties from a PowerPoint Presentation
The detailed steps for retrieving document properties from a PowerPoint presentation are as follows:
- Create an object of Presentation class.
- Load a presentation file using Presentation.loadFromFile() method.
- Get the properties of the presentation using Presentation.getDocumentProperty() method.
- Retrieve property information using methods under IDocumentProperty class and write it to a text file.
- Java
import com.spire.presentation.IDocumentProperty;
import com.spire.presentation.Presentation;
import java.io.FileWriter;
public class retrievePresentationProperties {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation presentation = new Presentation();
//Load a presentation file
presentation.loadFromFile("AddProperties.pptx");
//Get the properties of the presentation
IDocumentProperty property = presentation.getDocumentProperty();
//Get the properties and write them to a text file
String properties = "Title: " + property.getTitle() + "\r\n"
+ "Subject: " + property.getSubject() + "\r\n"
+ "Author: " + property.getAuthor() + "\r\n"
+ "Manager: " + property.getManager() + "\r\n"
+ "Company: " + property.getCompany() + "\r\n"
+ "Category: " + property.getCategory() + "\r\n"
+ "Keywords: " + property.getKeywords() + "\r\n"
+ "Comments: " + property.getComments();
FileWriter presentationProperties = new FileWriter("PresentationProperties.txt");
presentationProperties.write(properties);
presentationProperties.close();
}
}

Delete Document Properties of a PowerPoint Presentation
Removing document properties from a presentation is similar to adding properties. Just set the property data to null and the document properties can be removed. The details are as follows:
- Create an object of Presentation class.
- Load a presentation file using Presentation.loadFromFile() method.
- Get the document properties of the presentation using Presentation.getDocumentProperty() method.
- Set the document properties to null using methods under IDocumentProperty class.
- Save the presentation using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.IDocumentProperty;
import com.spire.presentation.Presentation;
public class deletePresentationProperties {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation presentation = new Presentation();
//Load a PowerPoint presentation
presentation.loadFromFile("AddProperties.pptx");
//Get the properties of the presentation and set the properties to null
IDocumentProperty property = presentation.getDocumentProperty();
property.setTitle("");
property.setSubject("");
property.setAuthor("");
property.setManager("");
property.setCompany("");
property.setCategory("");
property.setKeywords("");
property.setComments("");
//Save the presentation file
presentation.saveToFile("DeleteProperties.pptx", FileFormat.AUTO);
presentation.dispose();
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
This article will demonstrate how to set the layout of the slide via Spire.Presentation in Java applications. There are 11 kinds of layout on Microsoft PowerPoint and Spire.Presentation supports all of them.

Set one layout of the slide
import com.spire.presentation.*;
public class setSlideLayout {
public static void main(String[] args) throws Exception{
//Create an instance of presentation document
Presentation ppt = new Presentation();
//Remove the default slide
ppt.getSlides().removeAt(0);
//Append a slide and set the layout for slide
ISlide slide = ppt.getSlides().append(SlideLayoutType.TITLE);
//Add content for Title and Text
IAutoShape shape = (IAutoShape)slide.getShapes().get(0);
shape.getTextFrame().setText("Spire.Presentation");
shape = (IAutoShape)slide.getShapes().get(1);
shape.getTextFrame().setText("Set the Layout of Slide as Title");
//Save the document
ppt.saveToFile("SlideLayout.pptx", FileFormat.PPTX_2013);
ppt.dispose();
}
}

Set the different layout of the slides
import com.spire.presentation.*;
public class setDifferentSlideLayout {
public static void main(String[] args) throws Exception{
//Create a PPT document
Presentation presentation = new Presentation();
//Remove the default slide
presentation.getSlides().removeAt(0);
//Loop through slide layouts
for (SlideLayoutType type : SlideLayoutType.values())
{
//Append slide by specified slide layout
presentation.getSlides().append(type);
}
//Save the document
presentation.saveToFile("Result.pptx", FileFormat.PPTX_2013);
presentation.dispose();
}
}
Effective screenshot:

This article demonstrates how to split a PowerPoint document into multiple individual slides using Spire.Presentation for Java.
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
public class SplitPowerPoint {
public static void main(String[] args) throws Exception {
//Load the sample PowerPoint file
Presentation ppt = new Presentation();
ppt.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx");
//Loop through the slides
for (int i = 0; i < ppt.getSlides().getCount(); i++)
{
//Create an instance of Presentation class
Presentation newppt = new Presentation();
//Remove the default slide
newppt.getSlides().removeAt(0);
//Select a slide from the source file and append it to the new document
newppt.getSlides().append(ppt.getSlides().get(i));
//Save to file
newppt.saveToFile(String.format("output/result-%d.pptx",i), FileFormat.PPTX_2013);
}
}
}
Output:

This article demonstrates how to apply background image to all slides in a PowerPoint presentation using Spire.Presentation for Java.
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideBackground;
import com.spire.presentation.drawing.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
public class AppplyBgToAllSlides {
public static void main(String[] args) throws Exception {
//load a PowerPoint file
Presentation presentation = new Presentation();
presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\input.pptx");
//get the image data
BufferedImage bufferedImage = ImageIO.read(new FileInputStream("C:\\Users\\Administrator\\Desktop\\bg.jpg"));
IImageData imageData = presentation.getImages().append(bufferedImage);
//loop through the slides
for (int i = 0; i < presentation.getSlides().getCount() ; i++) {
//apply the image to the specific slide as background
SlideBackground background = presentation.getSlides().get(i).getSlideBackground();
background.setType(BackgroundType.CUSTOM);
background.getFill().setFillType(FillFormatType.PICTURE);
background.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
background.getFill().getPictureFill().getPicture().setEmbedImage(imageData);
}
//save the file
presentation.saveToFile("output/BackgroundImage.pptx", FileFormat.PPTX_2013);
presentation.dispose();
}
}

The slide master in PowerPoint preserves some fixed styles, such as background image, title and theme color, which can be inherited by other slides. This article demonstrates how to customize the slide masters in a PowerPoint file and apply them to different slides using Spire.Presentation for Java.
Apply One Slide Master in PowerPoint
import com.spire.presentation.*;
import com.spire.presentation.drawing.BackgroundType;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.IImageData;
import com.spire.presentation.drawing.PictureFillType;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
public class ModifyAndApplySlideMaster {
public static void main(String[] args) throws Exception {
//create a Presentation object and specify the slide size
Presentation presentation = new Presentation();
presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);
//get the first slide master
IMasterSlide masterSlide = presentation.getMasters().get(0);
//set the background image of the slide master
String backgroundPic = "C:/Users/Administrator/Desktop/bg.jpg";
BufferedImage image = ImageIO.read(new FileInputStream(backgroundPic));
IImageData imageData = presentation.getImages().append(image);
masterSlide.getSlideBackground().setType(BackgroundType.CUSTOM);
masterSlide.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
masterSlide.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
masterSlide.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData);
//add an image (company logo) to slide master
String logo = "C:/Users/Administrator/Desktop/logo.png";
image = ImageIO.read(new FileInputStream(logo));
imageData = presentation.getImages().append(image);
IEmbedImage imageShape = masterSlide.getShapes().appendEmbedImage(ShapeType.RECTANGLE,imageData,new Rectangle2D.Float(40,40,200,60));
imageShape.getLine().setFillType(FillFormatType.NONE);
//add some text (company name) to slide master
IAutoShape textShape = masterSlide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float((float) presentation.getSlideSize().getSize().getWidth()-200,(float) presentation.getSlideSize().getSize().getHeight()-60,200,30));//Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(ppt.SlideSize.Size.Width-200, ppt.SlideSize.Size.Height-60, 200, 30));
textShape.getTextFrame().setText("Chengdu E-iceblue Co., Ltd.");
textShape.getTextFrame().getTextRange().setFontHeight(15f);
textShape.getTextFrame().getTextRange().getFill().setFillType(FillFormatType.SOLID);
textShape.getTextFrame().getTextRange().getFill().getSolidColor().setColor(Color.blue);
textShape.getTextFrame().getTextRange().getParagraph().setAlignment(TextAlignmentType.CENTER);
textShape.getFill().setFillType(FillFormatType.NONE);
textShape.getLine().setFillType(FillFormatType.NONE);
//append a new slide
presentation.getSlides().append();
//save to file
presentation.saveToFile("ModifySlideMaster.pptx", FileFormat.PPTX_2013);
presentation.dispose();
}
}

Apply Multiple Slide Maters in PowerPoint
import com.spire.presentation.*;
import com.spire.presentation.drawing.BackgroundType;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.IImageData;
import com.spire.presentation.drawing.PictureFillType;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
public class CreateAndApplyMultiSlideMasters {
public static void main(String[] args) throws Exception {
//create a Presentation object and specify the slide size
Presentation presentation = new Presentation();
presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);
//add four new slides to the presentation
for (int i = 0; i < 4; i++)
{
presentation.getSlides().append();
}
//get the first slide master
IMasterSlide first_master = presentation.getMasters().get(0);
//create another slide master based on the first one
presentation.getMasters().appendSlide(first_master);
IMasterSlide second_master = presentation.getMasters().get(1);
//set different background images for the two masters
String pic1 = "C:/Users/Administrator/Desktop/image1.png";
String pic2 = "C:/Users/Administrator/Desktop/image2.png";
BufferedImage image = ImageIO.read(new FileInputStream(pic1));
IImageData imageData = presentation.getImages().append(image);
first_master.getSlideBackground().setType(BackgroundType.CUSTOM);
first_master.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
first_master.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
first_master.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData);
image = ImageIO.read(new FileInputStream(pic2));
imageData = presentation.getImages().append(image);
second_master.getSlideBackground().setType(BackgroundType.CUSTOM);
second_master.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
second_master.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
second_master.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData);
//apply the first master along with the layout to the first slide
presentation.getSlides().get(0).setLayout(first_master.getLayouts().get(6));
//apply the second master along with the layout to the rest slides
for (int i = 1; i < presentation.getSlides().getCount(); i++)
{
presentation.getSlides().get(i).setLayout(second_master.getLayouts().get(6));
}
//save to file
presentation.saveToFile("ApplyMultiMasters.pptx", FileFormat.PPTX_2013);
presentation.dispose();
}
}
