
Java设置PPT幻灯片背景——纯色、渐变、图片背景
发布日期:2021-05-09 00:35:47
浏览次数:17
分类:博客文章
本文共 3004 字,大约阅读时间需要 10 分钟。
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(); }}
图片背景效果:
(本文完)
转载请注明出处!
发表评论
最新留言
感谢大佬
[***.8.128.20]2025年04月16日 18时00分49秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
对模拟器虚假设备识别能力提升15%!每日清理大师App集成系统完整性检测
2021-05-09
使用Power BI构建数据仓库与BI方案
2021-05-09
pytest封神之路第二步 132个命令行参数用法
2021-05-09
Django认证系统并不鸡肋反而很重要
2021-05-09
快用Django REST framework写写API吧
2021-05-09
tep用户手册帮你从unittest过渡到pytest
2021-05-09
12张图打开JMeter体系结构全局视角
2021-05-09
Spring Boot 2.x基础教程:构建RESTful API与单元测试
2021-05-09
[UWP 自定义控件]了解模板化控件(1):基础知识
2021-05-09
UWP 自定义控件:了解模板化控件 系列文章
2021-05-09
[UWP]从头开始创建并发布一个番茄钟
2021-05-09
在 Azure 上执行一些简单的 python 工作
2021-05-09
WinUI 3 Preview 3 发布了,再一次试试它的性能
2021-05-09
使用命令把SpringBoot项目打包成可运行的jar包(简洁,操作性强)
2021-05-09
List数组排序
2021-05-09
VMware vSphere 离线虚拟机安装 BIND 9
2021-05-09
说说第一份工作
2021-05-09
dojo/request模块整体架构解析
2021-05-09
dojo/aspect源码解析
2021-05-09
Web性能优化:What? Why? How?
2021-05-09