News Category

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.

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>9.4.5</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);
    }
}

Java: Set Backgrounds for PowerPoint Presentations

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

Java: Set Backgrounds for PowerPoint Presentations

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

Java: Set Backgrounds for PowerPoint Presentations

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

Java: Set Backgrounds for PowerPoint Presentations

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

Java: Set Backgrounds for PowerPoint Presentations

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.

Picture files are among the most commonly used types of documents in people's lives. Sometimes, you may want to take all image files in a folder and convert them into slides for a PowerPoint presentation. Depending on your requirements, you can convert images to shapes or slide backgrounds. This article demonstrates how to convert images (in any common image format) to a PowerPoint document in Java using Spire.Presentation for Java.

Install Spire.Presentation for Java

First, 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>9.4.5</version>
    </dependency>
</dependencies>
    

Convert Images to Backgrounds in PowerPoint in Java

When images are converted as background of each slide in a PowerPoint document, they cannot be moved or scaled. The following are the steps to convert a set of images to a PowerPoint file as background images using Spire.Presentation for Java.

  • Create a Presentation object.
  • Set the slide size type to Sreen16x9.
  • Get the image paths from a folder.
  • Traverse through the images.
  • Get a specific image and append it to the image collection of the document using Presentation.getImages().append() method.
  • Add a slide to the document using Presentation.getSlides().append() method.
  • Set the image as the background of the slide using the methods under SlideBackground object.
  • Save the document to a PowerPoint file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;

public class ConvertImagesAsBackground {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Set slide size type
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //Remove the default slide
        presentation.getSlides().removeAt(0);

        //Get image files from a folder
        File directoryPath = new File("C:\\Users\\Administrator\\Desktop\\Images");
        File[] picFiles  = directoryPath.listFiles();

        //Loop through the images
        for (int i = 0; i < picFiles.length; i++)
        {
            //Add a slide
            ISlide slide = presentation.getSlides().append();

            //Get a specific image
            String imageFile = picFiles[i].getAbsolutePath();

            //Append it to the image collection
            BufferedImage bufferedImage =  ImageIO.read(new FileInputStream(imageFile));
            IImageData imageData = presentation.getImages().append(bufferedImage);

            //Set the image as the background image of the slide
            slide.getSlideBackground().setType(BackgroundType.CUSTOM);
            slide.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
            slide.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
            slide.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData);
        }

        //Save to file
        presentation.saveToFile("output/ImagesToBackground.pptx", FileFormat.PPTX_2013);
    }
}

Java: Convert Images (PNG, JPG, BMP, etc.) to PowerPoint

Convert Images to Shapes in PowerPoint in Java

If you would like the images are moveable and resizable in the PowerPoint file, you can convert them as shapes. Below are the steps to convert images to shapes in a PowerPoint document using Spire.Presentation for Java.

  • Create a Presentation object.
  • Set the slide size type to Sreen16x9.
  • Get the image paths from a folder.
  • Traverse through the images.
  • Get a specific image and append it to the image collection of the document using Presentation.getImages().append() method.
  • Add a slide to the document using Presentation.getSlides().append() method.
  • Add a shape with the size equal to the slide using ISlide.getShapes().appendShape() method.
  • Fill the shape with the image using the methods under FillFormat object.
  • Save the document to a PowerPoint file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

import javax.imageio.ImageIO;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;

public class ConvertImageToShape {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Set slide size type
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //Remove the default slide
        presentation.getSlides().removeAt(0);

        //Get image files from a folder
        File directoryPath = new File("C:\\Users\\Administrator\\Desktop\\Images");
        File[] picFiles  = directoryPath.listFiles();

        //Loop through the images
        for (int i = 0; i < picFiles.length; i++)
        {
            //Add a slide
            ISlide slide = presentation.getSlides().append();

            //Get a specific image
            String imageFile = picFiles[i].getAbsolutePath();

            //Append it to the image collection
            BufferedImage bufferedImage =  ImageIO.read(new FileInputStream(imageFile));
            IImageData imageData = presentation.getImages().append(bufferedImage);

            //Add a shape with the size equal to the slide
            IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float(0, 0, (float) presentation.getSlideSize().getSize().getWidth(), (float)presentation.getSlideSize().getSize().getHeight()));

            //Fill the shape with image
            shape.getLine().setFillType(FillFormatType.NONE);
            shape.getFill().setFillType(FillFormatType.PICTURE);
            shape.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
            shape.getFill().getPictureFill().getPicture().setEmbedImage(imageData);
        }

        //Save to file
        presentation.saveToFile("output/ImagesToShape.pptx", FileFormat.PPTX_2013);
    }
}

Java: Convert Images (PNG, JPG, BMP, etc.) to PowerPoint

Convert Images to PowerPoint with Customized Slide Size in Java

If the aspect ratio of your images is not 16:9, or they are not in a standard slide size, you can create slides based on the actual size of the pictures. This will prevent the image from being over stretched or compressed. The following are the steps to convert images to a PowerPoint document with customized slide size using Spire.Presentation for Java.

  • Create a Presentation object.
  • Create a PdfUnitConvertor object, which is used to convert pixel to point.
  • Get the image paths from a folder.
  • Traverse through the images.
  • Get a specific image and append it to the image collection of the document using Presentation.getImages().append() method.
  • Get the image width and height, and convert them to point.
  • Set the slide size of the presentation based on the image size using Presentation.getSlideSize().setSize() method.
  • Add a slide to the document using Presentation.getSlides().append() method.
  • Set the image as the background image of the slide using the methods under SlideBackground object.
  • Save the document to a PowerPoint file using Presentation.saveToFile() method.
  • Java
import com.spire.pdf.graphics.PdfGraphicsUnit;
import com.spire.pdf.graphics.PdfUnitConvertor;
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;

public class CustomizeSlideSize {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Remove the default slide
        presentation.getSlides().removeAt(0);

        //Get image files from a folder
        File directoryPath = new File("C:\\Users\\Administrator\\Desktop\\Images");
        File[] picFiles  = directoryPath.listFiles();

        //Create a PdfUnitConvertor object
        PdfUnitConvertor convertor = new PdfUnitConvertor();

        //Loop through the images
        for (int i = 0; i < picFiles.length; i++)
        {
            //Get a specific image
            String imageFile = picFiles[i].getAbsolutePath();

            //Append it to the image collection
            BufferedImage bufferedImage =  ImageIO.read(new FileInputStream(imageFile));
            IImageData imageData = presentation.getImages().append(bufferedImage);

            //Get image height and width in pixel
            int height = imageData.getHeight();
            int width = imageData.getWidth();

            //Convert pixel to point
            float widthPoint = convertor.convertUnits(width, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);
            float heightPoint= convertor.convertUnits(height, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);

            //Set slide size
            presentation.getSlideSize().setSize(new Dimension((int)widthPoint, (int)heightPoint));

            //Add a slide
            ISlide slide = presentation.getSlides().append();

            //Set the image as the background image of the slide
            slide.getSlideBackground().setType(BackgroundType.CUSTOM);
            slide.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
            slide.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
            slide.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData);
        }

        //Save to file
        presentation.saveToFile("output/CustomizeSlideSize.pptx", FileFormat.PPTX_2013);
    }
}

Java: Convert Images (PNG, JPG, BMP, etc.) to PowerPoint

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.

When we add a trademark, copyright or other symbol to our presentation, we might want the symbol to appear slightly above or below a certain text. In Microsoft PowerPoint, we can implement this effect simply by applying superscript or subscript formatting to the symbol. In this article, we will demonstrate how to achieve this task programmatically in Java 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>9.4.5</version>
    </dependency>
</dependencies>
    

Add Superscript and Subscript

Spire.Presentation for Java provides the PortionEx.getFormat().setScriptDistance(float value) method for applying superscript or subscript formatting to text. The value can be set as positive or negative. The bigger the positive value, the higher the superscript will appear above your text. The smaller the negative value, the lower the subscript will appear below your text.

The following are the steps to add superscript or subscript to a PowerPoint document:

  • Create a Presentation instance and load a PowerPoint document using Presentation.loadFromFile() method.
  • Get the desired slide using Presentation.getSlides().get() method.
  • Add a shape to the slide using ISlide.getShapes().appendShape() method and set shape fill type and line color.
  • Access the text frame of the shape using IAutoShape.getTextFrame() method, then clear the default paragraph in the text frame using ITextFrameProperties.getParagraphs().clear() method.
  • Create a paragraph using ParagraphEx class, and add normal text to the paragraph using ParagraphEx.setText() method.
  • Create a portion with text using PortionEx class, and then apply superscript or subscript formatting to the text using PortionEx.getFormat().setScriptDistance(float value) method.
  • Set text color, font and font size for the normal text and the superscript or subscript text.
  • Append the paragraph to the text frame of the shape using ITextFrameProperties.getParagraphs().append() method.
  • Save the result document using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

import java.awt.*;

public class AddSuperscriptAndSubscript {
    public static void main(String []args) throws Exception {

        //Load a PowerPoint document
        Presentation presentation = new Presentation();
        presentation.loadFromFile("template.pptx");

        //Get the first slide
        ISlide slide = presentation.getSlides().get(0);

        //Add a shape to the slide
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle(150, 100, 200, 50));
        shape.getFill().setFillType(FillFormatType.NONE);
        shape.getShapeStyle().getLineColor().setColor(Color.white);

        //Access the text frame of the shape
        ITextFrameProperties textFrame = shape.getTextFrame();
        //Clear the default paragraph in the text frame
        textFrame.getParagraphs().clear();

        //Create a paragraph with normal text
        ParagraphEx para = new ParagraphEx();
        para.setText("E=mc");
        
        //Create a portion with superscript text
        PortionEx tr = new PortionEx("2");
        tr.getFormat().setScriptDistance(40);
        
        //Append the portion to the paragraph
        para.getTextRanges().append(tr);
        
        para.getTextRanges().append(new PortionEx("\n"));

        //Set text color, font and font size for the normal text
        tr = para.getTextRanges().get(0);
        tr.getFill().setFillType(FillFormatType.SOLID);
        tr.getFill().getSolidColor().setColor(new Color(128,0,128));
        tr.setFontHeight(20);
        tr.setLatinFont(new TextFont("Arial"));
        
        //Set text color and font for the superscript text
        tr = para.getTextRanges().get(1);
        tr.getFill().setFillType(FillFormatType.SOLID);
        tr.getFill().getSolidColor().setColor(Color.BLUE);
        tr.setLatinFont(new TextFont("Arial"));

        //Append the paragraph to the text frame of the shape
        textFrame.getParagraphs().append(para);
        
        //Create another paragraph with normal text
        para = new ParagraphEx();
        para.setText("X");
        
        //Create a portion with subscript text
        tr = new PortionEx("100");
        tr.getFormat().setScriptDistance(-25);
        
        //Append the portion to the paragraph
        para.getTextRanges().append(tr);

        //Set text color, font and font size for the normal text
        tr = para.getTextRanges().get(0);
        tr.getFill().setFillType(FillFormatType.SOLID);
        tr.getFill().getSolidColor().setColor(new Color(128,0,128));
        tr.setFontHeight(20);
        tr.setLatinFont(new TextFont("Arial"));
        
        //Set text color and font for the subscript text
        tr = para.getTextRanges().get(1);
        tr.getFill().setFillType(FillFormatType.SOLID);
        tr.getFill().getSolidColor().setColor(Color.BLUE);
        tr.setLatinFont(new TextFont("Arial"));

        //Append the paragraph to the text frame of the shape
        textFrame.getParagraphs().append(para);

        //Save the result document
        presentation.saveToFile("AddSuperscriptAndSubscript.pptx", FileFormat.PPTX_2013);
    }
}

Output:

Java: Add Superscript and Subscript to PowerPoint

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.

PowerPoint documents signed with digital signatures can help recipients check if they have been altered since they were signed. If any changes are made, the signatures will become invalid immediately. Therefore, before you edit a PowerPoint document, you should check if it has been digitally signed or not. In this article, you will learn how to achieve this task programmatically in Java 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>9.4.5</version>
    </dependency>
</dependencies>
    

Verify if a PowerPoint Document is Digitally Signed

Spire.Presentation for Java provides the Presentation.isDigitallySigned() method to detect if a PowerPoint document is digitally signed or not. If the method returns true, then it means the document is digitally signed.

The following are the detailed steps to implement this function:

  • Create a Presentation instance.
  • Load a PowerPoint document using Presentation.loadFromFile() method.
  • Detect if the document is digitally signed or not using Presentation.isDigitallySigned() method.
  • Java
import com.spire.presentation.Presentation;

public class VerifyIfPPTisDigitallySigned {
    public static void main(String []args) throws Exception {
        //Create a Presentation instance
        Presentation ppt = new Presentation();
        //Load a PowerPoint document
        ppt.loadFromFile("Sample.pptx");

        //Verify if the document is digitally signed or not
        if (ppt.isDigitallySigned()) {
            System.out.println("This document is digitally signed");
        } else {
            System.out.println("This document is not digitally signed");
        }
    }
}

Java: Verify if a PowerPoint Document is Digitally Signed

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.

When an image appears over the text, the text will be covered by the image and will be unable to be displayed. At this point, you can set the transparency of the picture in order to show the text above the image. This article is to demonstrate how to insert an image into a specific slide position in PowerPoint and set its transparency 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.

  • Package Manager
<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>9.4.5</version>
    </dependency>
</dependencies>
    

Set Transparency for Images in PowerPoint

A number of classes and methods are involved in this code example, so a table shown as below is provided to make it easier for you to learn about them.

Name Description
IAutoShape Interface Represents a shape.
ShapeList Class Represents a collection of shapes.
PictureFillFormat Class Represents a picture fill style.
ShapeList.appendShape(ShapeType.shapeType, Rectangle2D.Double) Method Adds a new shape to list.
IAutoShape.getLine().setFillType(FillFormatType.value)  Method Sets the fill format type of the line.
IAutoShape.getFill().setFillType(FillFormatType.value) Method Sets the fill format type of a shape.
IAutoShape.getFill().getPictureFill() Method Gets the picture fill format.
PictureFillFormat.setFillType(PictureFillType.value) Method Sets the picture fill mode.
PictureFillFormat.getPicture().setUrl(java.lang.String value) Method Sets the image's URL for a picture fill.
PictureFillFormat.getPicture().setTransparency() Method Sets the transparency of a picture fill.

The following are some steps to set transparency for images in PowerPoint:

  • Create a Presentation instance and load a PowerPoint sample document using Presentation.loadFromFile() method.
  • Get a specified slide using Presentation.getSlides().get() method, and insert a shape to the specified position of the slide using ShapeList.appendShape(ShapeType.shapeType, Rectangle2D.Double) method.
  • Fill the shape with an image and set the fill format type using IAutoShape.getFill().setFillType(FillFormatType.value) method.
  • Get the picture fill format using IAutoShape.getFill().getPictureFill() method.
  • Set the picture fill mode using PictureFillFormat.setFillType(PictureFillType.value) method, set the image’s URL using PictureFillFormat.getPicture().setUrl(java.lang.String value) method, and set the transparency of the image using PictureFillFormat.getPicture().setTransparency() method.
  • Save the document using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import java.awt.geom.Rectangle2D;

public class SetImageTransparency {
    public static void main(String[] args) throws Exception {
        //Create a Presentation instance
        Presentation presentation = new Presentation();

        //Load a PowerPoint sample document
        presentation.loadFromFile("C:\\Users\\Test1\\Desktop\\sample.pptx");

        //Insert a shape to the specified position of the first slide
        Rectangle2D.Double rect1 = new   Rectangle2D.Double(50, 130, 275, 150);
        IAutoShape shape =  presentation.getSlides().get(1).getShapes().appendShape(ShapeType.RECTANGLE, rect1);

        //Fill the shape with an image
        shape.getLine().setFillType(FillFormatType.NONE);//Sets the fill format type
        shape.getFill().setFillType(FillFormatType.PICTURE);//Sets the type of filling
        shape.getFill().getPictureFill().getPicture().setUrl("https://cdn.e-iceblue.com/C:\\Users\\Test1\\Desktop\\Picture.png");//Sets the linked image's URL
        shape.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);//Sets the picture fill mode

        //Set transparency of the image
        shape.getFill().getPictureFill().getPicture().setTransparency(50);

        //Save the document to file
        presentation.saveToFile("output/SetImageTransparency_result.pptx", FileFormat.PPTX_2010);
    }
}

Java: Set Transparency for Images in PowerPoint

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: Convert ODP to PDF

2021-11-04 05:19:34 Written by support iceblue

The OpenDocument Presentation Document Format, commonly referred to as ODP, is one of the file extensions of an Open Document Format file and is designed to serve as an open-source display format for slideshow presentations. Sometimes you may need to convert an ODP file to PDF to ensure the document's formatting remains intact. In this article, you will learn how to achieve this function 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>9.4.5</version>
    </dependency>
</dependencies>
    

Convert ODP to PDF

You can convert ODP to PDF using Spire.Presentation for Java in an easy and quick manner by following the steps listed below.

  • Create a Presentation object.
  • Load a sample ODP document using Presentation.loadFromFile() method.
  • Save the document as PDF using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;

public class ODPtoPDF {
    public static void main(String[] args) throws Exception {

        //Create a Presentation instance
        Presentation presentation = new Presentation();

        //Load a sample ODP file
        presentation.loadFromFile("toPDF.odp",FileFormat.ODP);
        
        //Save it as PDF
        presentation.saveToFile("output/Result.pdf", FileFormat.PDF);
    }
}

The original file:

Java: Convert ODP to PDF

The generated file:

Java: Convert ODP to 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.

Hyperlinks in PowerPoint are clickable objects that enable you to jump to another slide in the same/different PowerPoint document or to a specific website. They are a great way to add additional resources to your slides, and they can also make the document more interactive. In addition to adding hyperlinks to PowerPoint documents, Spire.Presentation for Java also supports modifying and removing the existing hyperlinks. This article is going to introduce how to achieve the above two functions.

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>9.4.5</version>
    </dependency>
</dependencies>
    

Modify Hyperlinks in PowerPoint

With Spire.Presentation for Java, you are allowed to set a new hyperlink address and display text for the existing hyperlink. The following are the detailed steps to modify a hyperlink in PowerPoint.

  • Create a Presentation object and load a PowerPoint document using Presentation.loadFromFile() method.
  • Get a specified slide using Presentation.getSlides().get() method.
  • Get the shapes of the specified slide using getShapes() method under ISlide interface, and then get the specified shape that contains the hyperlink using ShapeList.get() method.
  • Get the text range of the existing hyperlink using IAutoShape.getTextFrame().getTextRange() method, and then set a new hyperlink display text for the text range using PortionEx.setText() method.
  • Get the existing clickable hyperlink of the text range using TextCharacterProperties.getClickAction() method, and then set a new hyperlink address using ClickHyperlink.setAddress() method.
  • Save the document to file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;

public class modifyHyperlink {
    public static void main(String[] args) throws Exception {

        //Create a Presentation object and load a PowerPoint document
        Presentation presentation = new Presentation();
        presentation.loadFromFile("test.pptx");

        //Get the shape that contains the hyperlink
        IAutoShape shape = (IAutoShape)presentation.getSlides().get(0).getShapes().get(0);

        //Edit the hyperlink text and address
        shape.getTextFrame().getTextRange().setText("Spire.Presentation for Java");
        shape.getTextFrame().getTextRange().getClickAction().setAddress("https://www.e-iceblue.com/Introduce/presentation-for-java.html");

        //Save to file.
        presentation.saveToFile("ModifyHyperlink.pptx", FileFormat.PPTX_2013);
    }
}

Java: Modify or Remove Hyperlinks in PowerPoint

Remove Hyperlinks in PowerPoint

When a hyperlink needs to be removed for some reason, Spire.Persentation for Java provides the TextCharacterProperties.setClickAction() method. And by setting its value to null, you could remove the hyperlink easily in PowerPoint. The detailed steps are as follows:

  • Create a Presentation object and load a PowerPoint document using Presentation.loadFromFile() method.
  • Get a specified slides using Presentation.getSlides().get() method.
  • Get the shapes of the specified slide using getShapes() method under ISlide interface, and then get the specified shape that contains the hyperlink using ShapeList.get() method.
  • Get the text range of the existing hyperlink using IAutoShape.getTextFrame().getTextRange() method, and then remove the hyperlink by setting the value of the TextCharacterProperties.setClickAction() method to null.
  • Save the document to file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;

public class removeHyperlink {
    public static void main(String[] args) throws Exception {

        //Create a Presentation object and load a PowerPoint document
        Presentation presentation = new Presentation();
        presentation.loadFromFile("test.pptx");

        //Get the shape that contains the hyperlink.
        IAutoShape shape = (IAutoShape)presentation.getSlides().get(0).getShapes().get(0);

        //Set the click action to null to remove the hyperlink.
        shape.getTextFrame().getTextRange().setClickAction(null);

        //Save to file.
        presentation.saveToFile("RemoveHyperlink.pptx", FileFormat.PPTX_2013);
    }
}

Java: Modify or Remove Hyperlinks in PowerPoint

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 scatter (XY) chart is a two-dimensional chart that shows the relationship between two sets of variables. Each scatter chart has two axes: a horizontal axis (x-axis) and a vertical axis (y-axis), and it accepts only one data series. In this article, you will learn how to add a scatter chart to a PowerPoint slide 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>9.4.5</version>
    </dependency>
</dependencies>
    

Create a Scatter Chart in PowerPoint

Spire.Presentation for Java provides the ShapeCollection.appendChart(ChartType type, Rectangle2D rectangle, boolean init) method to add charts of a certain type to a presentation slide. The ChartType enumeration pre-defines 73 chart types, including scatter chart, column chart, pie chart, etc. The following are the main steps to add a scatter chart in PowerPoint.

  • Create a Presentation object.
  • Append a scatter chart to the specific slide using ShapeCollection.appendChart() method.
  • Set the chart data through ChartData.get().setValue() method.
  • Set the chart title, axes titles, series labels, etc. using the methods under IChart interface.
  • Set the grid line style and data point line style.
  • Save the document to file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideSizeType;
import com.spire.presentation.TextLineStyle;
import com.spire.presentation.charts.ChartType;
import com.spire.presentation.charts.IChart;
import com.spire.presentation.charts.entity.ChartDataLabel;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class CreateScatterChart {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //Add a scatter chart to the first slide
        IChart chart = presentation.getSlides().get(0).getShapes().appendChart(ChartType.SCATTER_SMOOTH_LINES_AND_MARKERS,new Rectangle2D.Float(40, 80, 550, 320),false);

        //Set the chart title
        chart.getChartTitle().getTextProperties().setText("Scatter Chart");
        chart.getChartTitle().getTextProperties().isCentered(true);
        chart.getChartTitle().setHeight(20f);
        chart.hasTitle(true);

        //Set the chart data
        Double[] xData = new Double[] { 1.0, 2.4, 5.0, 8.9 };
        Double[] yData = new Double[] { 5.3, 15.2, 6.7, 8.0 };
        chart.getChartData().get(0,0).setText("X-Values");
        chart.getChartData().get(0,1).setText("Y-Values");
        for (int i = 0; i < xData.length; i++) {
            chart.getChartData().get(i+1,0).setValue(xData[i]);
            chart.getChartData().get(i+1,1).setValue(yData[i]);
        }

        //Set the series label
        chart.getSeries().setSeriesLabel(chart.getChartData().get("B1","B1"));

        //Set the X and Y values
        chart.getSeries().get(0).setXValues(chart.getChartData().get("A2","A5"));
        chart.getSeries().get(0).setYValues(chart.getChartData().get("B2","B5"));

        //Add data labels
        for (int i = 0; i < 4; i++)
        {
            ChartDataLabel dataLabel = chart.getSeries().get(0).getDataLabels().add();
            dataLabel.setLabelValueVisible(true);
        }

        //Set the primary axis title and the secondary axis title
        chart.getPrimaryValueAxis().hasTitle(true);
        chart.getPrimaryValueAxis().getTitle().getTextProperties().setText("X-Axis Title");
        chart.getSecondaryValueAxis().hasTitle(true);
        chart.getSecondaryValueAxis().getTitle().getTextProperties().setText("Y-Axis Title");

        //Set the grid line
        chart.getSecondaryValueAxis().getMajorGridTextLines().setFillType(FillFormatType.SOLID);
        chart.getSecondaryValueAxis().getMajorGridTextLines().setStyle(TextLineStyle.THIN_THIN);
        chart.getSecondaryValueAxis().getMajorGridTextLines().getSolidFillColor().setColor(Color.GRAY);
        chart.getPrimaryValueAxis().getMajorGridTextLines().setFillType(FillFormatType.NONE);

        //Set the data point line
        chart.getSeries().get(0).getLine().setFillType(FillFormatType.SOLID);
        chart.getSeries().get(0).getLine().setWidth(0.1f);
        chart.getSeries().get(0).getLine().getSolidFillColor().setColor(Color.BLUE);

        //Save the document to file
        presentation.saveToFile("output/ScatterChart.pptx", FileFormat.PPTX_2016);
    }
}

Java: Create a Scatter Chart in PowerPoint

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 digital signature confirms that the document content originates from the signer and has not been changed. In this article, you will learn how to add a digital signature to your PowerPoint documents as well as remove all digital signatures using Spire.Presentation for Java.

Installl 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>9.4.5</version>
    </dependency>
</dependencies>
    

Add a Digital Signature to PowerPoint

The following are the steps to add a digital signature to a PowerPoint document.

  • Create an object of Presentation class.
  • Load the sample PowerPoint document using Presentation.loadFromFile() method.
  • Add a digital signature to the document using Presentation.addDigitalSignature(String pfxPath, String password, String comments, java.util.Date signTime) method.
  • Save the result to a .pptx file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

import java.util.Date;

public class AddDigitalSignature {
    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Load the sample PowerPoint document
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx");

        //Add a digital signature
        String pfxPath = "C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx";
        String password = "e-iceblue";
        String comment = "Modification is not allowed";
        presentation.addDigitalSignature(pfxPath,password,comment,new Date());

        //Save the result to file
        presentation.saveToFile("output/AddDigitalSignature.pptx", FileFormat.PPTX_2013);
    }
}

Java: Add or Remove Digital Signatures in PowerPoint

Remove all Digital Signaters from PowerPoint

The following are steps to remove all digital signatures from a PowerPoint document.

  • Create an object of Presentation class.
  • Load the sample PowerPoint document using Presentation.loadFromFile() method.
  • Determine if the document contains digital signatures using Presentation.isDigitallySigned() method.
  • Remove all signatures using Presentation.removeAllDigitalSignatures() method.
  • Save the result to a .pptx file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

public class RemoveDigitalSignature {
    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Load the sample PowerPoint document
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\AddDigitalSignature.pptx");

        //Determine if the document is digitally signed
        if (presentation.isDigitallySigned() == true)
        {
            //Remove all digital signatures
            presentation.removeAllDigitalSignatures();
        }

        //Save the result to file
        presentation.saveToFile("output/RemoveDigitalSignature.pptx", FileFormat.PPTX_2013);
    }
}

Java: Add or Remove Digital Signatures in PowerPoint

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

Java: Change the Slide Size in PowerPoint

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

Java: Change the Slide Size in PowerPoint

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.

Page 1 of 6