关于java: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”。更加具体的步骤可参考此教程。

<repositories>
<repository>
<id>com.e-iceblue</id>
<url>http://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation.free</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>

最初,导入成果如下图所示:

代码示例

import com.spire.presentation.*;
public class AddFooter {
    public static void main(String[] args) throws Exception {
        //加载PPT示例文档
 Presentation presentation = new Presentation();
        presentation.loadFromFile("C:UsersTest1DesktopSample.pptx");
        //增加页脚
 presentation.setFooterText("正飞传媒有限公司");
        //设置页脚为可见
 presentation.setFooterVisible(true);
        //设置页码为可见
 presentation.setSlideNumberVisible(true);
        //设置日期为可见
 presentation.setDateTimeVisible(true);
        //保留后果文档
 presentation.saveToFile("output/AddFooter.pptx", FileFormat.PPTX_2010);
    }
}

效果图:

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理