当前位置: 移动技术网 > IT编程>开发语言>Java > 浅谈Java设置PPT幻灯片背景——纯色、渐变、图片背景

浅谈Java设置PPT幻灯片背景——纯色、渐变、图片背景

2019年07月19日  | 移动技术网IT编程  | 我要评论

乌台诗案的受害者,阿呆与阿瓜下载,祁汉个人资料

ppt幻灯片生成时,系统默认是无色背景填充,幻灯片设计需要手动设置背景效果,可设置颜色填充或者图片背景填充。本文将对此介绍具体实现方法。

jar文件导入方法(参考):

步骤1:在java程序中可新建一个文件夹命名为lib,并将下载包中的jar文件复制到新建的文件夹下。

步骤2:复制文件后,添加到引用类库:选中这个jar文件,点击鼠标右键,选择“build path” – “add to build path”。完成引用。

java示例1:设置背景颜色

1.纯色背景

import com.spire.presentation.*;import com.spire.presentation.drawing.*;public class backgroundcolor { 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.pink);

 ppt.savetofile(outputfile, fileformat.pptx_2010);
 ppt.dispose();
 }
}

纯色背景效果:

2.渐变背景

import java.awt.color;import com.spire.presentation.*;import com.spire.presentation.drawing.*;public class backgroundcolor { public static void main(string[] args) throws exception {
 string inputfile = "test.pptx";
 string outputfile = "output/setbackgroundcolor2.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();
 }
}

渐变色背景效果:

java示例2:图片背景

import com.spire.presentation.*;import com.spire.presentation.drawing.*;public class imagebackground { public static void main(string[] args) throws exception {
 string inputfile = "input.pptx";
 string imagefile = "1.png";
 string outputfile = "output/imgbackgroundcolor.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().seturl((new java.io.file(imagefile)).getabsolutepath()); 
 ppt.savetofile(outputfile, fileformat.pptx_2010);
 ppt.dispose();
 }
}

图片背景效果:

以上所述是小编给大家介绍的java设置ppt幻灯片背景——纯色、渐变、图片背景详解整合,希望对大家有所帮助

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网