Java sets the background color and background image for PowerPoint documents

The background is very important when creating a Powerpoint document. If you unify the background, the Powerpoint presentation will look beautiful. In this article, I will show you how to use Free Spire.Presentation for Java in a Java application to set a solid background color and a gradient background color, and to add a background image for PowerPoint slides.

** Import JAR package ** ** Method 1: ** After downloading and unzipping Free Spire.Presentation for Java, in the lib folder Import the Spire.Presentation.jar package into your Java application as a dependency.

** Method 2: ** After installing the JAR package directly from the Maven repository, configure the pom.xml file as follows:

<repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation.free</artifactId>
        <version>2.6.1</version>
    </dependency>
</dependencies>

** Set a solid background color: **

import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

import java.awt.*;

public class PPTbackground {

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

        //Import PowerPoint document
        Presentation ppt = new Presentation();
        ppt.loadFromFile("file1.pptx");

        //Get the number of slides
        int slideCount = ppt.getSlides().getCount();

        ISlide slide = null;

        //Loop through the slides and set a solid background color for each slide
        for(int i = 0; i < slideCount;i++) {
            slide = ppt.getSlides().get(i);
            slide.getSlideBackground().setType(BackgroundType.CUSTOM);

            //Set a solid background fill
            slide.getSlideBackground().getFill().setFillType(FillFormatType.SOLID);
            slide.getSlideBackground().getFill().getSolidColor().setColor(Color.PINK);
        }
        //Save the result file
        ppt.saveToFile("bg1.pptx", FileFormat.PPTX_2010);
    }
}

** Effect image of plain background: ** p1.jpg

** Set the background color of the gradient: **

import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

import java.awt.*;

public class PPTbackground {

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

        //Import PowerPoint document
        Presentation ppt = new Presentation();
        ppt.loadFromFile("file1.pptx");

        //Get the number of slides
        int slideCount = ppt.getSlides().getCount();

        ISlide slide = null;

        //Traverse slides and set a gradient background color for each slide
        for(int i = 0; i < slideCount;i++) {
            slide = ppt.getSlides().get(i);
            slide.getSlideBackground().setType(BackgroundType.CUSTOM);

            //Set the gradient background color fill
            slide.getSlideBackground().getFill().setFillType(FillFormatType.GRADIENT);
            slide.getSlideBackground().getFill().getGradient().getGradientStops().append(0, Color.WHITE);
            slide.getSlideBackground().getFill().getGradient().getGradientStops().append(1, Color.PINK);

        }
        //Save the result file
        ppt.saveToFile("bg2.pptx", FileFormat.PPTX_2010);
    }
}

** Effect image of gradient background color: ** p2.jpg

** Add background image: **

import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

import java.awt.*;

public class PPTbackground {

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

        //Import PowerPoint document
        Presentation ppt = new Presentation();
        ppt.loadFromFile("file1.pptx");

        //Get the number of slides
        int slideCount = ppt.getSlides().getCount();
        ISlide slide = null;

        //Loop through the slides and add a background image to each slide
        for(int i = 0; i < slideCount;i++) {
            slide = ppt.getSlides().get(i);
            slide.getSlideBackground().setType(BackgroundType.CUSTOM);

            //Set the background fill of the image
            slide.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
            slide.getSlideBackground().getFill().getPictureFill().setAlignment(RectangleAlignment.NONE);
            slide.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
            slide.getSlideBackground().getFill().getPictureFill().getPicture().setUrl((new java.io.File("background.jpg ")).getAbsolutePath());

        }
        //Save the result file
        ppt.saveToFile("bg3.pptx", FileFormat.PPTX_2010);
    }
}

** Effect of adding background image: ** p3.jpg

Recommended Posts

Java sets the background color and background image for PowerPoint documents
Java Excel settings background color and background image
[Android Studio] Set an arbitrary image for the application background [Java]
Learn for the first time java # 3 expressions and operators
Prepare the environment for java11 and javaFx with Ubuntu 18.4
Java sets different background colors for adjacent rows in Excel
Java while and for statements
JavaFX-Load Image in the background
Java settings word Page background color
Java Excel Insertion and Image Extraction
AWS SDK for Java 1.11.x and 2.x
Java PowerPoint password setting and cancellation
Classes and instances Java for beginners
About the procedure for java to work
[Java] for Each and sorted in Lambda
[For beginners] Difference between Java and Kotlin
Java Programming Style Guide for the Java 11 Era
[Java 7] Divide the Java list and execute the process
Learning for the first time java [Introduction]
[Java] Proxy for logging SQL and SQL results
[Java] Color the standard output to the terminal
[Java8] Search the directory and get the file
Display the background image in the production environment
Impressions and doubts about using java for the first time in Android Studio
[Deep Learning from scratch] in Java 1. For the time being, differentiation and partial differentiation