· 

Java - Insert Lists in PowerPoint

To create an effective PowerPoint presentation, it is important to make the slides easy for the audience to read. One of the most common methods is to format text as a bulleted or numbered list. Once you have added a list to your presentation, you may also want to make it more visible by changing the bullet style, e.g., customize the bullet symbol with an image.

 

In this article, I am going to introduce how to programmatically preform the above mentioned tasks by using Spire.Presentation for Java.

Installing Spire.Presentation.jar

If you use Maven, you can easily import the Spire.Presentation.jar in your application using the following configurations. For non-Maven projects, please download the jar file from this link and add it as a dependency in your program.

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

Example 1. Insert a numbered list

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

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

public class InsertNumberedList {

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

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

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

       
//Insert a shape
       
Rectangle2D rect = new Rectangle2D.Double(50, 70, 400, 200);
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.
RECTANGLE, rect);
        shape.getFill().setFillType(FillFormatType.
NONE);
        shape.getLine().setFillType(FillFormatType.
NONE);

       
//Remove default paragraphs from the shape
       
shape.getTextFrame().getParagraphs().clear();

       
//Specify list content
       
String[] listContent = new String[]{
               
" Provide a clear, concise navigation method",
               
" Make it intuitively easy to use",
               
" Keep it consistent",
               
" Degrade gracefully",
               
" Write it with your target audience in mind",
               
" Make sure its compliant"
       
};

       
//Add a numbered list
       
for (int i = 0; i < listContent.length; i++) {
            ParagraphEx paragraph =
new ParagraphEx();
            shape.getTextFrame().getParagraphs().append(paragraph);
            paragraph.setText(listContent[i]);
            paragraph.getTextRanges().get(
0).getFill().setFillType(FillFormatType.SOLID);
            paragraph.getTextRanges().get(
0).getFill().getSolidColor().setColor(Color.black);
            paragraph.setBulletType(TextBulletType.
NUMBERED);
            paragraph.setBulletStyle(NumberedBulletStyle.
BULLET_ARABIC_PERIOD);
        }

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

Example 2. Insert a bulleted list

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

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

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

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

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

       
//Insert a shape
       
Rectangle2D rect = new Rectangle2D.Double(50, 70, 400, 200);
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.
RECTANGLE, rect);
        shape.getFill().setFillType(FillFormatType.
NONE);
        shape.getLine().setFillType(FillFormatType.
NONE);

       
//Remove default paragraphs from the shape
        
shape.getTextFrame().getParagraphs().clear();

       
//Specify list content
       
String[] listContent = new String[]{
               
" Provide a clear, concise navigation method",
               
" Make it intuitively easy to use",
                
" Keep it consistent",
               
" Degrade gracefully",
               
" Write it with your target audience in mind",
               
" Make sure its compliant"
       
};

       
//Add a bulleted list
       
for (int i = 0; i < listContent.length; i++) {
            ParagraphEx paragraph =
new ParagraphEx();
            shape.getTextFrame().getParagraphs().append(paragraph);
            paragraph.setText(listContent[i]);
            paragraph.getTextRanges().get(
0).getFill().setFillType(FillFormatType.SOLID);
            paragraph.getTextRanges().get(
0).getFill().getSolidColor().setColor(Color.black);
            paragraph.setBulletType(TextBulletType.
SYMBOL);
            paragraph.setBulletChar(
'\u25AA');
        }

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

Example 3. Customize bullet symbol with a picture

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

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

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

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

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

       
//Insert a shape
       
Rectangle2D rect = new Rectangle2D.Double(50, 70, 400, 200);
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.
RECTANGLE, rect);
        shape.getFill().setFillType(FillFormatType.
NONE);
        shape.getLine().setFillType(FillFormatType.
NONE);

       
//Remove default paragraphs from the shape
        
shape.getTextFrame().getParagraphs().clear();

       
//Specify list content
       
String[] listContent = new String[]{
               
" Provide a clear, concise navigation method",
               
" Make it intuitively easy to use",
                
" Keep it consistent",
               
" Degrade gracefully",
               
" Write it with your target audience in mind",
               
" Make sure its compliant"
       
};

       
//Load an image as the bullet symbol
       
BufferedImage image = ImageIO.read(new File("C:\\Users\\Administrator\\Desktop\\icon.png"));

       
//Add a custom bullet list with the picture
       
for (int i = 0; i < listContent.length; i++) {
            ParagraphEx paragraph =
new ParagraphEx();
            shape.getTextFrame().getParagraphs().append(paragraph);
            paragraph.setText(listContent[i]);
            paragraph.getTextRanges().get(
0).getFill().setFillType(FillFormatType.SOLID);
            paragraph.getTextRanges().get(
0).getFill().getSolidColor().setColor(Color.black);
            paragraph.setBulletType(TextBulletType.
PICTURE);
            paragraph.getBulletPicture().setEmbedImage(slide.getPresentation().getImages().append(image));
        }

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

Write a comment

Comments: 0