本文介绍如何使用spire.prensetaion for java为powerpoint中的文本设置透明色。
import com.spire.presentation.*;
import com.spire.presentation.drawing.fillformattype;
import java.awt.*;
import java.awt.geom.rectangle2d;
public class applytransparency {
public static void main(string[] args) throws exception {
//创建prensetaion对象
presentation presentation = new presentation();
presentation.getslidesize().settype(slidesizetype.screen_16_x_9);
//添加一个图形
iautoshape textbox = presentation .getslides().get(0).getshapes().appendshape(shapetype.rectangle,new rectangle2d.float(50, 70, 300, 120));
textbox.getshapestyle().getlinecolor().setcolor(new color(1,1,1,0));
textbox.getfill().setfilltype(fillformattype.none);
//删除默认段落
textbox.gettextframe().getparagraphs().clear();
//添加三个段落,并对段落文字设置不同透明度的颜色
int alpha = 55;
for (int i = 0; i < 3; i )
{
textbox.gettextframe().getparagraphs().append(new paragraphex());
textbox.gettextframe().getparagraphs().get(i).gettextranges().append(new portionex("text transparency"));
textbox.gettextframe().getparagraphs().get(i).gettextranges().get(0).getfill().setfilltype(fillformattype.none);
textbox.gettextframe().getparagraphs().get(i).gettextranges().get(0).getfill().setfilltype(fillformattype.solid);
textbox.gettextframe().getparagraphs().get(i).gettextranges().get(0).getfill().getsolidcolor().setcolor(new color(176, 48, 96, alpha));
alpha = 100;
}
//保存文档
presentation.savetofile("texttransparency.pptx", fileformat.pptx_2013);
}
}