Java adds a text box to PowerPoint slides

A text box refers to a movable and resizable text or graphic container. In PowerPoint, if you need to add new content, you often need to insert a new text box. In this article, how to use Free Spire.Presentation for Java to add a textbox to a PowerPoint slide and set the textbox border style, fill effect, shadow effect, textbox rotation, textstyle and more.

** Import JAR package ** ** Method 1: ** Download Free Spire.Presentation for Java, unzip it, and in the lib folder Import the Spire.Presentation.jar package into your Java application as a dependency. ** Method 2: ** Install the JAR package directly from the Maven repository and 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>

** Java code **

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.GradientShapeType;
import com.spire.presentation.drawing.OuterShadowEffect;

import java.awt.*;

public class AddTextBox {
    public static void main(String[]args)throws Exception {
        //Create document
        Presentation ppt = new Presentation();

        //Takes the first slide and adds a rectangular textbox of the specified size and position
        IAutoShape tb = ppt.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE,new Rectangle(80, 120, 550, 200));

        //Set the border style of the text box
        tb.getLine().setFillType(FillFormatType.SOLID);
        tb.getLine().setWidth(2.5);
        tb.getLine().getSolidFillColor().setColor(Color.white);

        //Add text to the text box and format the text
        tb.appendTextFrame("Thanks for watching!\n Thanks for Watching");
        PortionEx textRange = tb.getTextFrame().getTextRange();
        textRange.getFill().setFillType(FillFormatType.SOLID);
        textRange.getFill().getSolidColor().setColor(Color.white);
        textRange.setFontHeight(30);
        textRange.setLatinFont(new TextFont("Arial Unicode MS"));

        //Fill the text box with a gradient color
        tb.getFill().setFillType(FillFormatType.GRADIENT);
        tb.getFill().getGradient().setGradientShape(GradientShapeType.LINEAR);
        tb.getFill().getGradient().getGradientStops().append(1f,KnownColors.LIGHT_SEA_GREEN);
        tb.getFill().getGradient().getGradientStops().append(0f,KnownColors.LIGHT_PINK);

        //Set the shadow effect of the text box
        OuterShadowEffect shadowEffect= new OuterShadowEffect();
        shadowEffect.setBlurRadius(20);
        shadowEffect.setDirection(30);
        shadowEffect.setDistance(8);
        shadowEffect.getColorFormat().setColor(Color.LIGHT_GRAY);
        tb.getEffectDag().setOuterShadowEffect(shadowEffect);

        //Set the text box to rotate 5 degrees to the right (rotate to the left sets the value to a negative number)
        tb.setRotation(5);

        //Save the document
        ppt.saveToFile("addTextBox.pptx",FileFormat.PPTX_2013);
        ppt.dispose();
    }
}

** Result of adding text box: ** ppt.jpg

Recommended Posts

Java adds a text box to PowerPoint slides
Java adds SmartArt graphics to PowerPoint
Convert Java Powerpoint to XPS
Java adds table to PDF
Java to extract PDF text content
How to make a Java container
Java adds hyperlinks to Word documents
[Java] How to create a folder
How to make a Java array
Java adds form fields to PDF
Add / remove watermark to Java PowerPoint
How to make a Java calendar Summary
[Introduction to Java] How to write a Java program
How to make a Discord bot (Java)
How to print a Java Word document
How to display a web page in Java
java I tried to break a simple block
To become a VB.net programmer from a Java shop
I did Java to make (a == 1 && a == 2 && a == 3) always true
Try to create a bulletin board in Java
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
How to convert a solidity contract to a Java contract class
A story about trying to operate JAVA File
Java adds page numbers to existing PDF documents
I tried to break a block with java (1)
Java introductory text
[Java] Introduction to Java
Introduction to java
A brief introduction to terasoluna5, see the text below
Submit a job to AWS Batch with Java (Eclipse)
How to jump from Eclipse Java to a SQL file
java: How to write a generic type list [Note]
[Android / Java] Set up a button to return to Fragment
Send me a roadmap to becoming a full-fledged Java engineer
[Java] Text extraction from PowerPoint (ppt) using Apache POI
I tried to create a Clova skill in Java
How to create a data URI (base64) in Java
[Java] How to get a request by HTTP communication
I tried to make a login function in Java
[Java] How to execute tasks on a regular basis
[Java] How to cut out a character string character by character
[Java] How to erase a specific character from a character string
How to convert A to a and a to A using AND and OR in Java
How to convert a file to a byte array in Java
Try to solve a restricted FizzBuzz problem in Java
Try to build a Java development environment using Docker
[Java] How to start a new line with StringBuilder