本文介绍如何使用spire.presneatation for java将简单的html字符串添加到幻灯片。
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 {
//创建presentation对象
presentation ppt = new presentation();
//添加图形到第一个幻灯片
iautoshape shape = ppt.getslides().get(0).getshapes().appendshape(shapetype.rectangle, new rectangle2d.float(50, 50, 400, 100));
shape.getfill().setfilltype(fillformattype.none);
//清除图形中默认的段落
shape.gettextframe().getparagraphs().clear();
//定义html字符串
string htmlstring = ""
"- spire.presentation for java
"
"- spire.pdf for java
"
"- spire.doc for java
"
"- spire.barcode for java
"
"
";
//添加html字符串到段落
shape.gettextframe().getparagraphs().addfromhtml(htmlstring);
//保存文档
ppt.savetofile("inserthtml.pptx", fileformat.pptx_2013);
}
}