Insert HTML String in PowerPoint in Java

This article demonstrates how to render text with simple HTML tags to formatted text in a presentation slide by using Spire.Presentation for Java.

import com.spire.presentation.FileFormat;
import com.spire.presentation.IAutoShape;
import com.spire.presentation.Presentation;
import com.spire.presentation.ShapeType;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.geom.Rectangle2D;

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

        //create a Presentation object
        Presentation ppt = new Presentation();
        
        //add a shape to the first slide
        IAutoShape shape = ppt.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float(50, 50, 400, 100));
        shape.getFill().setFillType(FillFormatType.NONE);

        //clear the default paragraph
        shape.getTextFrame().getParagraphs().clear();

        //define html string
        String htmlString = "<ul>" +
                            "<li style=\"color:blue\">Spire.Presentation for Java</li>" +
                            "<li style=\"color:green\">Spire.PDF for Java</li>" +
                            "<li style=\"color:gray\">Spire.Doc for Java</li>" +
                            "<li style=\"color:red\">Spire.Barcode for Java</li>" +
                            "</ul>";

        //insert html string in the shape
        shape.getTextFrame().getParagraphs().addFromHtml(htmlString);

        //save to file
        ppt.saveToFile("output/InsertHtml.pptx", FileFormat.PPTX_2013);
    }
}

Insert HTML String in PowerPoint in Java