Spire.Cloud.Excel 将 Excel 保存为 PDF

 

Spire.Cloud.Excel SDK Java提供GeneralApi接口和WorkbookApi接口,支持将本地Excel工作簿和云端Excel文档转换为ODS, PDF, XPS, PCL, PS等格式。本文将介绍如何分别调用GeneralApi接口和WorkbookApi接口将Excel 文档保存为PDF格式。

首先,请通过 Maven 仓库安装 Spire.Cloud Web API Jar 包及依赖。其次,需要在冰蓝云官网(https://cloud.e-iceblue.cn/)注册账号,创建我的应用程序,获得 APP ID 及 App Key。

我们为每个账户提供了2G免费内存,在”文档管理” 目录下面可以看到转换成功的PDF文档效果图:

Spire.Cloud.Excel 将 Excel 保存为 PDF

GeneralApi接口支持将本地的Excel文档保存为云端PDF:

import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.GeneralApi;
import spire.cloud.excel.sdk.model.ExportFormat;

import java.io.File;

public class CloudWord {
    //配置账号信息
    static String appId = "您的冰蓝云应用程序AppID ";
    static String appKey = "您的冰蓝云应用程序AppKey";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration configuration = new Configuration(appId, appKey, baseUrl);
    public static void main(String[] args) throws Exception  {
    //创建ConvertAPI实例
    GeneralApi generalApi = new GeneralApi(configuration);

    //支持的转换格式 Xlsx/Xls/Xlsb/Ods/Pdf/Xps/Ps/Pcl
    String format = ExportFormat.PDF.toString();
    //配置相关参数
    String outPath = "output/ConvertInRequestToPath.pdf ";
    File document = new File("D:/inputFile/Sample.xlsx");
    String password = null;
    //调用convertInRequestToPath接口将文档保存为PDF
    generalApi.convertInRequestToPath(format, outPath, document, password);

    }
}

WorkbookApi接口支持将云端的Excel文档保存为云端PDF:

import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.WorkbookApi;
import spire.cloud.excel.sdk.model.*;

public class CloudWord {
    //配置账号信息
    static String appId = "Your AppID";
    static String appKey = "Your AppKey";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration configuration = new Configuration(appId, appKey, baseUrl);
    public static void main(String[] args) throws Exception  {
    //创建WorkbookAPI实例
    WorkbookApi workbookApi = new WorkbookApi(configuration);

    String name = "Sample.xlsx";
    String outPath = "output/Result.pdf";
    String format = ExportFormat.PDF.toString();//Supported formats: XLSX/XLS/XLSB/ODS/PDF/XPS/PS/PCL
    ExportOptions options = null;
    String password = null;
    String storage = null;
    String folder = "input";
    workbookApi.convertWorkbookToPath(name, outPath, format, options, password, storage, folder);
    }
}

示例文档:

Spire.Cloud.Excel 将 Excel 保存为 PDF

PDF效果图:

Spire.Cloud.Excel 将 Excel 保存为 PDF