Spire.Presentation for Java (83)
Children categories
Animation can make a PowerPoint document more dynamic. In this article, we'll introduce how to add animations to shapes in a PowerPoint document using Spire.Presentation for Java.
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.animation.AnimationEffectType;
import java.awt.*;
import java.awt.geom.Rectangle2D;
public class SetAnimation {
public static void main(String[] args) throws Exception {
//create a PowrePoint document
Presentation ppt = new Presentation();
//add a slide
ISlide slide = ppt.getSlides().get(0);
//Add a shape to slide
IAutoShape shape = slide.getShapes().appendShape(ShapeType.CUBE, new Rectangle2D.Double(50, 150, 150, 150));
shape.getFill().setFillType(FillFormatType.SOLID);
shape.getFill().getSolidColor().setColor(Color.orange);
shape.getShapeStyle().getLineColor().setColor(Color.white);
//Add animation to the shape
slide.getTimeline().getMainSequence().addEffect(shape, AnimationEffectType.FADED_SWIVEL);
//save the document
ppt.saveToFile("AddAnimationToShape.pptx", FileFormat.PPTX_2013);
}
}

When you are collaborating on a PowerPoint document with your team members, adding comments is the most effective way to give feedbacks or communicate the changes you need to make on a particular slide. Once a comment has been added, you may also need to edit or delete it later. This article will demonstrate how to programmatically add, change or delete comments in a PowerPoint Document using Spire.Presentation for Java.
- Add a Comment to a Presentation Slide in Java
- Change a Comment in a Presentation Slide in Java
- Delete a Comment from a Presentation Slide in 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>11.1.1</version>
</dependency>
</dependencies>
Add a Comment to a Presentation Slide in Java
Spire.Presentation for Java offers the ISlide.addComment() method to add comments to a specified PowerPoint slide. The following are the steps to add a PowerPoint comment.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.loadFromFile() method.
- Add the author of the comment using Presentation.getCommentAuthors().addAuthor() method.
- Get a specified slide using Presentation.getSlides().get() method, and then add a comment to the slide using ISlide.addComment(ICommentAuthor author, java.lang.String text, java.awt.geom.Point2D position, java.util.Date dateTime) method.
- Save the result document using Presentation.saveToFile() method.
- Java
import com.spire.presentation.*;
import java.awt.geom.Point2D;
public class AddComment {
public static void main(String[] args) throws Exception{
//Initialize an instance of Presentation class
Presentation ppt = new Presentation();
//Load a sample PowerPoint document
ppt.loadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.pptx");
//Add the author of the comment
ICommentAuthor author = ppt.getCommentAuthors().addAuthor("E-iceblue", "Comment:");
//Add a comment to the specified slide
ppt.getSlides().get(0).addComment(author, "The first comment", new Point2D.Float(350, 170), new java.util.Date());
//Save the result document
ppt.saveToFile("AddComment.pptx", FileFormat.PPTX_2013);
ppt.dispose();
}
}

Change a Comment in a Presentation Slide in Java
To update or modify the content of an existing comment, you can use the ISlide.getComments().setText() method. The following are the steps to change a PowerPoint comment.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.loadFromFile() method.
- Get a specified slide using Presentation.getSlides().get() method.
- Replace a specified comment in the slide using ISlide.getComments().setText() method.
- Save the result document using Presentation.saveToFile() method.
- Java
import com.spire.presentation.*;
public class ReplaceComment {
public static void main(String[] args) throws Exception{
//Initialize an instance of Presentation class
Presentation ppt = new Presentation();
//Load a sample PowerPoint document
ppt.loadFromFile("AddComment.pptx");
//Get the first slide
ISlide slide = ppt.getSlides().get(0);
//Replace a specified comment in the slide
slide.getComments()[0].setText("Summary of Spire.Presentation for Java functions");
//Save the result document
ppt.saveToFile("ReplaceComment.pptx", FileFormat.PPTX_2013);
ppt.dispose();
}
}

Delete a Comment from a Presentation Slide in Java
Spire.Presentation for Java also allows you to remove comments from a specified slide using ISlide.deleteComment() method. The detailed steps are as follows.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.loadFromFile() method.
- Get a specified slide using Presentation.getSlides().get() method.
- Remove a specified comment from the slide using ISlide.deleteComment(Comment comment) method.
- Save the result document using Presentation.saveToFile() method.
- Java
import com.spire.presentation.*;
public class DeleteComment {
public static void main(String[] args) throws Exception{
//Initialize an instance of Presentation class
Presentation ppt = new Presentation();
//Load a sample PowerPoint document
ppt.loadFromFile("AddComment.pptx");
//Get the first slide
ISlide slide = ppt.getSlides().get(0);
//Remove a specified comment from the slide
slide.deleteComment(slide.getComments()[0]);
//Save the result document
ppt.saveToFile("DeleteComment.pptx", FileFormat.PPTX_2013);
ppt.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.
Java: Add, Modify, or Remove Footers in PowerPoint Documents
2024-04-12 09:13:00 Written by AdministratorAdding, modifying, and removing footers in PowerPoint documents is crucial as footers can provide additional information and organizational structure to the document. By including page numbers, dates, author information, or custom text in the footer, it can help the audience better understand the presentation content and track document versions. Footers also enhance the professionalism and tidiness of the document, making it more visually appealing and readable. Modifying footers allows for updating information or adjusting formats as needed to ensure the document remains current and consistent. Removing footers can customize the document's appearance based on specific requirements or design preferences. This article will introduce how to use Spire.Presentation for Java to add, modify, and remove footers in PowerPoint documents within a Java project.
- Java Add Footers in PowerPoint Documents
- Java Modify Footers in PowerPoint Documents
- Java Remove Footers in PowerPoint Documents
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>11.1.1</version>
</dependency>
</dependencies>
Java Add Footers in PowerPoint Documents
Using Spire.Presentation, you can easily add consistent footer content to the bottom of each page in a PowerPoint document. By adding footer placeholders, page number placeholders, and time placeholders, you can ensure that the footer content on each page remains consistent. Here are the detailed steps:
- Create a lisentation object.
- Load a PowerPoint document using the lisentation.loadFromFile() method.
- Set the footer visible using lisentation.setFooterVisible(true) and set the footer text.
- Set the slide number visible using lisentation.setSlideNumberVisible(true), iterate through each slide, check for the lisence of a page number placeholder, and modify the text to the "Page X" format if found.
- Set the date and time visible using lisentation.setDateTimeVisible(true).
- Set the format of the date using the lisentation.setDateTime() method.
- Save the document to a specified path using the lisentation.saveToFile() method.
- Java
import com.spire.presentation.*;
import java.util.Date;
public class AddFooter {
public static void main(String[] args) throws Exception {
// Create a Presentation object
Presentation presentation = new Presentation();
// Load the presentation from a file
presentation.loadFromFile("Sample1.pptx");
// Set the footer visible
presentation.setFooterVisible(true);
// Set the footer text to "Spire.Presentation"
presentation.setFooterText("Spire.Presentation");
// Set the slide number visible
presentation.setSlideNumberVisible(true);
// Iterate through each slide in the presentation
for (int i = 0; i < presentation.getSlides().getCount(); i++) {
ISlide slide = presentation.getSlides().get(i);
for (int j = 0; j < slide.getShapes().getCount(); j++) {
IShape shape = slide.getShapes().get(j);
if (shape.getPlaceholder() != null) {
// If it is a slide number placeholder
if (shape.getPlaceholder().getType().equals(PlaceholderType.SLIDE_NUMBER)) {
IAutoShape shape1 = (IAutoShape) shape;
ParagraphEx paragraph = shape1.getTextFrame().getTextRange().getParagraph();
String text = paragraph.getText();
// Modify the slide number text to "Page X"
paragraph.setText("Page " + text);
}
}
}
}
// Set the date time visible
presentation.setDateTimeVisible(true);
// Create a Date object to represent the current time
Date currentDate = new Date();
// Set the date time format
presentation.setDateTime(currentDate, "MM/dd/yyyy");
// Save the modified presentation to a file
presentation.saveToFile("AddedFooter.pptx", FileFormat.PPTX_2016);
// Release the resources of the Presentation object
presentation.dispose();
}
}

Java Modify Footers in PowerPoint Documents
To modify the footer in a PowerPoint document, you need to inspect each shape on every slide to identify footer placeholders, page number placeholders, and so on. By recognizing these placeholders, you can set specific content and formats for each type. Here are the detailed steps:
- Create a Presentation object.
- Load a PowerPoint document using the Presentation.loadFromFile() method.
- Retrieve a slide using the Presentation.getSlides().get(index) method.
- Iterate through the shapes on the slide using a for loop, inspect each shape to determine if it is a placeholder for the footer, page number, etc., and then modify its content or format accordingly.
- Save the document to a specified path using the Presentation.saveToFile() method.
- Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.*;
public class ModifyFooter {
public static void main(String[] args) throws Exception {
// Create a Presentation object
Presentation presentation = new Presentation();
// Load a presentation from a file
presentation.loadFromFile("Sample2.pptx");
// Get the first slide
ISlide slide = presentation.getSlides().get(0);
// Iterate through shapes on the slide
for (int i = 0; i < slide.getShapes().getCount(); i++) {
// Check if the shape is a placeholder
if (slide.getShapes().get(i).getPlaceholder() != null) {
// Get the placeholder type
PlaceholderType type = slide.getShapes().get(i).getPlaceholder().getType();
// If it's a footer placeholder
if (type == PlaceholderType.FOOTER) {
// Convert the shape to IAutoShape type
IAutoShape autoShape = (IAutoShape) slide.getShapes().get(i);
// Set the text content to "E-ICEBLUE"
autoShape.getTextFrame().setText("E-ICEBLUE");
// Modify the font of the text
ChangeFont(autoShape.getTextFrame().getParagraphs().get(0));
}
// If it's a slide number placeholder
if (type == PlaceholderType.SLIDE_NUMBER) {
// Convert the shape to IAutoShape type
IAutoShape autoShape = (IAutoShape) slide.getShapes().get(i);
// Modify the font of the text
ChangeFont(autoShape.getTextFrame().getParagraphs().get(0));
}
}
}
// Save the modified presentation to a file
presentation.saveToFile("ModifiedFooter.pptx", FileFormat.PPTX_2016);
// Dispose of the Presentation object resources
presentation.dispose();
}
static void ChangeFont(ParagraphEx paragraph)
{
// Iterate through each text range in the paragraph
for (int i = 0; i < paragraph.getTextRanges().getCount(); i++) {
// Set the text style to italic
paragraph.getTextRanges().get(i).isItalic(TriState.TRUE);
// Set the text font
paragraph.getTextRanges().get(i).setEastAsianFont (new TextFont("Times New Roman"));
// Set the text font size to 34
paragraph.getTextRanges().get(i).setFontHeight(34);
// Set the text color
paragraph.getTextRanges().get(i).getFill().setFillType(FillFormatType.SOLID);
paragraph.getTextRanges().get(i).getFill().getSolidColor().setColor(Color.BLUE);
}
}
}

Java Remove Footers in PowerPoint Documents
To delete the footer in a PowerPoint document, you first need to retrieve content such as footer placeholders, page number placeholders, time placeholders, etc., within the slides. Once these placeholders are identified, you can locate and remove them from the collection of shapes on the slide. Here are the detailed steps:
- Create a Presentation object.
- Load a PowerPoint document using the Presentation.loadFromFile() method.
- Retrieve a slide using the Presentation.getSlides().get(index) method.
- Iterate through the shapes on the slide using a for loop, check if they are placeholders, and if they are footer placeholders, page number placeholders, time placeholders, remove them from the slide.
- Save the document to a specified path using the Presentation.saveToFile() method.
- Java
import com.spire.presentation.*;
public class RemoveFooter {
public static void main(String[] args) throws Exception {
// Create a Presentation object
Presentation presentation = new Presentation();
// Load the presentation from a file
presentation.loadFromFile("Sample2.pptx");
// Get the first slide
ISlide slide = presentation.getSlides().get(0);
// Iterate through the shapes on the slide
for (int i = slide.getShapes().getCount() - 1; i >= 0; i--) {
// Check if the shape is a placeholder
if (slide.getShapes().get(i).getPlaceholder() != null) {
// Get the placeholder type
PlaceholderType type = slide.getShapes().get(i).getPlaceholder().getType();
// If it's a footer placeholder
if (type == PlaceholderType.FOOTER) {
// Remove it from the slide
slide.getShapes().removeAt(i);
}
// If it's a slide number placeholder
if (type == PlaceholderType.SLIDE_NUMBER) {
// Remove it from the slide
slide.getShapes().removeAt(i);
}
// If it's a date and time placeholder
if (type == PlaceholderType.DATE_AND_TIME) {
// Remove it from the slide
slide.getShapes().removeAt(i);
}
}
}
// Save the modified presentation to a file
presentation.saveToFile("RemovedFooter.pptx", FileFormat.PPTX_2016);
// Dispose of the Presentation object resources
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.
A combination chart is a chart that combines at least two chart types in a single chart. This article introduces how to combine clustered column and line chart in PowerPoint using Spire.Presentation for Java.
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.charts.ChartType;
import com.spire.presentation.charts.IChart;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.geom.Rectangle2D;
public class CombinationChart {
public static void main(String[] args) throws Exception {
//create a PowerPoint document
Presentation presentation = new Presentation();
//insert a column clustered chart
Rectangle2D.Double rect = new Rectangle2D.Double(50, 100, 550, 300);
IChart chart = presentation.getSlides().get(0).getShapes().appendChart(ChartType.COLUMN_CLUSTERED, rect);
//set chart title
chart.getChartTitle().getTextProperties().setText("Sales vs. Unit Price");
chart.getChartTitle().getTextProperties().isCentered(true);
chart.getChartTitle().setHeight(30);
chart.hasTitle(true);
//write data to chart as chart data
chart.getChartData().get(0,0).setText("Month");
chart.getChartData().get(0,1).setText("Unit Price");
chart.getChartData().get(0,2).setText("Sales");
chart.getChartData().get(1,0).setText("January");
chart.getChartData().get(1,1).setNumberValue(120);
chart.getChartData().get(1,2).setNumberValue(5600);
chart.getChartData().get(2,0).setText("February");
chart.getChartData().get(2,1).setNumberValue(100);
chart.getChartData().get(2,2).setNumberValue(7300);
chart.getChartData().get(3,0).setText("March");
chart.getChartData().get(3,1).setNumberValue(80);
chart.getChartData().get(3,2).setNumberValue(10200);
chart.getChartData().get(4,0).setText("April");
chart.getChartData().get(4,1).setNumberValue(120);
chart.getChartData().get(4,2).setNumberValue(5900);
chart.getChartData().get(5,0).setText("May");
chart.getChartData().get(5,1).setNumberValue(90);
chart.getChartData().get(5,2).setNumberValue(9500);
chart.getChartData().get(6,0).setText("June");
chart.getChartData().get(6,1).setNumberValue(110);
chart.getChartData().get(6,2).setNumberValue(7200);
//set series labels
chart.getSeries().setSeriesLabel(chart.getChartData().get("B1", "C1"));
//set categories labels
chart.getCategories().setCategoryLabels(chart.getChartData().get("A2", "A7"));
//assign data to series values
chart.getSeries().get(0).setValues(chart.getChartData().get("B2", "B7"));
chart.getSeries().get(1).setValues(chart.getChartData().get("C2", "C7"));
//change the chart type of series 2 to line with markers
chart.getSeries().get(1).setType(ChartType.LINE_MARKERS);
//plot data of series 2 on the secondary axis
chart.getSeries().get(1).setUseSecondAxis(true);
//hide grid links of secondary axis
chart.getSecondaryValueAxis().getMajorGridTextLines().setFillType(FillFormatType.NONE);
//set overlap
chart.setOverLap(-50);
//set gap width
chart.setGapDepth(200);
//save the document
presentation.saveToFile("CombinationChart.pptx", FileFormat.PPTX_2010);
}
}

XPS (XML Paper Specification) is a fixed-format document described by an XML-based language. It maintains a consistent appearance for documents, which is an ideal file format for publishing, archiving and transmitting. This article will demonstrate how to programmatically convert PowerPoint to XPS 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>11.1.1</version>
</dependency>
</dependencies>
Convert PowerPoint to XPS
The detailed steps are as follows:
- Create a Presentation instance.
- Load a sample PowerPoint document using Presentation.loadFromFile() method.
- Save the PowerPoint document to XPS using Presentation.saveToFile(java.lang.String file, FileFormat fileFormat) method.
- Java
import com.spire.presentation.*;
public class PowerPointtoXPS {
public static void main(String[] args) throws Exception{
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a sample PowerPoint file
ppt.loadFromFile("E:\\Files\\test.pptx");
//Save to XPS file
ppt.saveToFile("toXPS.xps", FileFormat.XPS);
ppt.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 demonstrates how to align text within a table cell in PowerPoint using Spire.Presenatation for Java.
Code Snippets
import com.spire.presentation.*;
public class AlignTextInTableCell {
public static void main(String[] args) throws Exception {
//create a PowerPoint file
Presentation presentation = new Presentation();
//add a table
Double[] widths = new Double[]{100d, 200d, 100d, 100d};
Double[] heights = new Double[]{30d, 70d, 70d};
ITable table = presentation.getSlides().get(0).getShapes().appendTable(30,80, widths, heights);
table.setStylePreset(TableStylePreset.NONE);
//set the horizontal alignment for the cells in the first row
table.get(0, 0).getTextFrame().setText("Left");
table.get(0, 0).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.LEFT);
table.get(1, 0).getTextFrame().setText("Horizontal Center");
table.get(1, 0).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.CENTER);
table.get(2, 0).getTextFrame().setText("Right");
table.get(2, 0).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.RIGHT);
table.get(3, 0).getTextFrame().setText("Justify");
table.get(3, 0).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.JUSTIFY);
//Set the vertical alignment for the cells in the second row
table.get(0, 1).getTextFrame().setText("Top");
table.get(0, 1).setTextAnchorType(TextAnchorType.TOP);
table.get(1, 1).getTextFrame().setText("Vertical Center");
table.get(1, 1).setTextAnchorType(TextAnchorType.CENTER);
table.get(2, 1).getTextFrame().setText("Bottom");
table.get(2, 1).setTextAnchorType(TextAnchorType.BOTTOM);
//set the both horizontal and vertical alignment for the cells in the third row
table.get(0, 2).getTextFrame().setText("Top Left");
table.get(0, 2).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.LEFT);
table.get(0, 2).setTextAnchorType(TextAnchorType.TOP);
table.get(1, 2).getTextFrame().setText("Center");
table.get(1, 2).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.CENTER);
table.get(1, 2).setTextAnchorType(TextAnchorType.CENTER);
table.get(2, 2).getTextFrame().setText("Bottom Right");
table.get(2, 2).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.RIGHT);
table.get(2, 2).setTextAnchorType(TextAnchorType.BOTTOM);
//save to file
presentation.saveToFile("output/Alignment.pptx", FileFormat.PPTX_2013);
presentation.dispose();
}
}
Output

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();
}
}

When a PowerPoint presentation is converted to PDF, its document layout and formatting are fixed. Recipients can view the converted document without having Microsoft PowerPoint to be installed, but they can not modify it easily. In this article, we will demonstrate how to convert PowerPoint presentations to PDF in Java using Spire.Presentation for Java library.
- Convert a Whole PowerPoint Presentation to PDF
- Convert Specific Slide of a PowerPoint Presentation to PDF
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>11.1.1</version>
</dependency>
</dependencies>
Convert a Whole PowerPoint Presentation to PDF in Java
The following steps show you how to convert a whole PowerPoint presentation to PDF:
- Initialize an instance of Presentation class.
- Load the PowerPoint presentation using Presentation.loadFromFile() method.
- Save it to PDF using Presentation.saveToFile(filePath, FileFormat.PDF) method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
public class ConvertPowerPointToPDF {
public static void main(String []args) throws Exception {
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a PowerPoint presentation
ppt.loadFromFile("Sample.pptx");
//Save it as PDF
ppt.saveToFile("ToPdf1.pdf", FileFormat.PDF);
}
}

Convert Specific Slide of a PowerPoint Presentation to PDF in Java
The following steps show you how to convert a specific slide of a PowerPoint presentation to PDF:
- Initialize an instance of Presentation class.
- Load the PowerPoint presentation using Presentation.loadFromFile() method.
- Get the desired slide by its index using Presentation.getSlides().get(slideIndex) method.
- Save it to PDF using ISlide.saveToFile(filePath, FileFormat.PDF) method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
public class ConvertSlidesToPDF {
public static void main(String []args) throws Exception {
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a PowerPoint presentation
ppt.loadFromFile("Sample.pptx");
//Get the second slide
ISlide slide= ppt.getSlides().get(1);
//Save the slide to PDF
slide.saveToFile("ToPdf2.pdf", FileFormat.PDF);
}
}

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 the row height and column width of an existing table in a PowerPoint document using Spire.Presentation for Java.
Below is the screenshot of the input PowerPoint document:

import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.ITable;
import com.spire.presentation.Presentation;
public class Table_Row_Height_and_Column_Width {
public static void main(String[] args) throws Exception {
//Load the PowerPoint document
Presentation ppt = new Presentation();
ppt.loadFromFile("Table.pptx");
//Get the first slide
ISlide slide = ppt.getSlides().get(0);
//Get the first table in the slide
ITable table = (ITable) slide.getShapes().get(0);
//Change the height of the first table row and the width of the first table column
table.getTableRows().get(0).setHeight(100);
table.getColumnsList().get(0).setWidth(250);
//Save the document
ppt.saveToFile("Output.pptx", FileFormat.PPTX_2013);
ppt.dispose();
}
}
Output:

This article demonstrates how to insert an image to a table cell in PowerPoint using Spire.Presentataion for Java.
import com.spire.presentation.FileFormat;
import com.spire.presentation.ITable;
import com.spire.presentation.Presentation;
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 InsertImageToTableCell {
public static void main(String[] args) throws Exception {
//create a Presentation object and load an example PowerPoint file
Presentation presentation = new Presentation();
presentation.loadFromFile("C:/Users/Administrator/Desktop/example.pptx");
//append a table to the first slide
Double[] widths = new Double[]{100d,100d};
Double[] heights = new Double[]{100d,100d};
ITable table = presentation.getSlides().get(0).getShapes().appendTable(100,100, widths, heights);
//insert an image to the cell(0,0)
table.get(0,0).getFillFormat().setFillType(FillFormatType.PICTURE);
table.get(0,0).getFillFormat().getPictureFill().setFillType(PictureFillType.STRETCH);
BufferedImage bufferedImage = ImageIO.read(new FileInputStream("C:/Users/Administrator/Desktop/logo.png"));
IImageData imageData = presentation.getImages().append(bufferedImage);
table.get(0,0).getFillFormat().getPictureFill().getPicture().setEmbedImage(imageData);
//save to file
presentation.saveToFile("InsertImageToCell.pptx", FileFormat.PPTX_2013);
}
}
