该示例将详细讲述如何使用spire.presentation for java在java应用程序中为幻灯片设置纯色背景颜色,渐变背景颜色以及添加背景图片。
设置背景图片
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
public class pptbackground {
public static void main(string[] args) throws exception {
string inputfile = "sample.pptx";
string imagefile = "1.png";
string outputfile = "output/setbackgroundcolor.pptx";
presentation ppt = new presentation();
ppt.loadfromfile(inputfile);
ppt.getslides().get(0).getslidebackground().settype(backgroundtype.custom);
//设置文档的背景填充模式为图片填充
ppt.getslides().get(0).getslidebackground().getfill().setfilltype(fillformattype.picture);
ppt.getslides().get(0).getslidebackground().getfill().getpicturefill().setalignment(rectanglealignment.none);
ppt.getslides().get(0).getslidebackground().getfill().getpicturefill().setfilltype(picturefilltype.stretch);
ppt.getslides().get(0).getslidebackground().getfill().getpicturefill().getpicture().set).getabsolutepath());
ppt.savetofile(outputfile, fileformat.pptx_2010);
ppt.dispose();
}
}
设置纯色背景颜色
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
public class pptbackground {
public static void main(string[] args) throws exception {
string inputfile = "sample.pptx";
string outputfile = "output/setbackgroundcolor.pptx";
presentation ppt = new presentation();
ppt.loadfromfile(inputfile);
ppt.getslides().get(0).getslidebackground().settype(backgroundtype.custom);
//设置文档的背景填充模式为纯色填充,设置颜色
ppt.getslides().get(0).getslidebackground().getfill().setfilltype(fillformattype.solid);
ppt.getslides().get(0).getslidebackground().getfill().getsolidcolor().setcolor(java.awt.color.light_gray);
ppt.savetofile(outputfile, fileformat.pptx_2010);
ppt.dispose();
}
}
设置渐变色背景颜色
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import java.awt.*;
public class pptbackground {
public static void main(string[] args) throws exception {
string inputfile = "sample.pptx";
string outputfile = "output/setgradientcolor.pptx";
presentation ppt = new presentation();
ppt.loadfromfile(inputfile);
ppt.getslides().get(0).getslidebackground().settype(backgroundtype.custom);
//设置文档的背景填充模式为渐变色填充,设置颜色
ppt.getslides().get(0).getslidebackground().getfill().setfilltype(fillformattype.gradient);
ppt.getslides().get(0).getslidebackground().getfill().getgradient().getgradientstops().append(0, color.white);
ppt.getslides().get(0).getslidebackground().getfill().getgradient().getgradientstops().append(1,color.green);
ppt.savetofile(outputfile, fileformat.pptx_2010);
ppt.dispose();
}
}