Java 添加页脚到PowerPoint文档

前言

在制作PowerPoint幻灯片时,可能会遇到需要将页码、时间、公司名称等具有标志性内容添加到幻灯片的情况。此时我们可以通过插入页眉页脚方式来实现上述操作。本文将利用Free Spire.Presentation for Java免费控件在Java程序中演示如何将含有页码、时间、公司名称的页脚添加到PowerPoint幻灯片中。

测试环境搭建

在运行代码前,需要搭建测试环境。首先下载安装配置好JDK和Intellij IDEA,然后将控件里的Jar包导入IDEA即可。这里提供两种导入方式给大家。其一,直接在官网上下载安装包,解压后找到lib文件夹下的Spire.Presentation.jar,最后将其手动导入IDEA。其二推荐使用),在IDEA中创建一个Maven项目,然后在pom.xml文件中键入以下代码,最后点击“Import Changes”。更加详细的步骤可参考此教程。

       

            com.e-iceblue

            http://repo.e-iceblue.cn/repository/maven-public/

       

   

   

        e-iceblue

        spire.presentation.free

        3.9.0

   

最后,导入效果如下图所示:

代码示例

import com.spire.presentation.*;

public class AddFooter {

public static void main(String[] args) throws Exception{

//加载PPT示例文档

Presentation presentation = new Presentation();

presentation.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pptx");

//添加页脚

presentation.setFooterText("演示文稿示例");

//设置页脚为可见

presentation.setFooterVisible(true);

//设置页码为可见

presentation.setSlideNumberVisible(true);

//设置日期为可见

presentation.setDateTimeVisible(true);

//保存结果文档

presentation.saveToFile("output/AddFooter.pptx", FileFormat.PPTX_2010);

    }

}

效果图:

你可能感兴趣的:(Java 添加页脚到PowerPoint文档)