ppt幻灯片生成时,系统默认是无色背景填充,幻灯片设计需要手动设置背景效果,可设置颜色填充或者图片背景填充。本文将对此介绍具体实现方法。
jar文件导入方法(参考):
步骤1:在java程序中可新建一个文件夹命名为lib,并将下载包中的jar文件复制到新建的文件夹下。
步骤2:复制文件后,添加到引用类库:选中这个jar文件,点击鼠标右键,选择“build path” – “add to build path”。完成引用。
java示例1:设置背景颜色
1.纯色背景
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
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.渐变背景
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
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:图片背景
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
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幻灯片背景——纯色、渐变、图片背景详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对快网idc网站的支持!
原文链接:https://www.imooc.com/article/282027
相关文章
猜你喜欢
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-29 94
-
2025-05-29 97
-
2025-05-29 16
-
2025-05-25 104
-
2025-05-25 79
热门评论






