Insert an Image to a PowerPoint Table in Java

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

Insert an Image to a PowerPoint Table in Java