Spire.Cloud.PowerPoint 添加图片到 PowerPoint 文档

 

Spire.Cloud.PowerPoint提供了ImagesApi接口支持给PowerPoint文档添加图片。本文将介绍如何使用该接口实现添加图片。

步骤一:创建一个Maven程序,通过Maven仓库安装Spire.Cloud.SDK,详细步骤可参考这篇文章

步骤二:通过冰蓝云官网 https:/cloud.e-iceblue.cn/ 注册账号并登陆,在“我的应用”版块创建应用程序,获得App ID及App Key。

步骤三:将示例PowerPoint文档上传至冰蓝云官网的“文档管理”版块。

Spire.Cloud.PowerPoint 添加图片到 PowerPoint 文档

步骤四:在Maven程序中编写代码调用ImagesApi接口给示例PowerPoint文档添加图片。

import spire.cloud.powerpoint.sdk.ApiException;
import spire.cloud.powerpoint.sdk.Configuration;
import spire.cloud.powerpoint.sdk.api.ImagesApi;

import java.io.File;

public class AddImage {
    static String appId = "APP ID";
    static String appKey = "APP Key";
    static String baseUrl = "https://api.e-iceblue.cn";

    public static void main(String[] args) throws ApiException {
        //配置APP ID和APP Key
        Configuration configuration = new Configuration(appId, appKey, baseUrl);
        //创建ImagesApi实例
        ImagesApi imagesApi = new ImagesApi(configuration);

        //PowerPoint文档名称
        String name = "addSlideImage.pptx";
        //图片路径
        String imagePath = "C:/Users/Administrator/Desktop/flowers and sunset.jpg";
        //获取图片
        File imageData = new File(imagePath);
        //PowerPoint文档打开密码,无密码则为null
        String password = null;
        //PowerPoint文档存放的文件夹
        String folder = null;
        //使用冰蓝云默认的存储空间
        String storage = null;
        //需要添加图片的幻灯片索引
        int slideIndex = 0;
        //图片插入位置的横坐标
        double x = 150;
        //图片插入位置的纵坐标
        double y = 50;
        //图片的宽度
        double width = 500;
        //图片的高度
        double height = 250;
        //调用addSlideImage方法添加图片到PowerPoint文档
        imagesApi.addSlideImage(name, slideIndex, x, y, width, height, imageData, password, folder, storage);
    }
}

使用Spire.Cloud在线编辑查看生成PowerPoint文档效果图:

Spire.Cloud.PowerPoint 添加图片到 PowerPoint 文档