Java converts Excel to PDF based on Spire.Cloud.Excel

Spire.Cloud.Excel SDK Java provides the general API interface and WorkbookApi interface, and supports the conversion of local excel and cloud EXCEL documents to ODS, PDF, XPS, PCL, PS and other formats. This paper introduces the steps and methods of format conversion, taking the conversion of Excel form to PDF as an example.

Necessary steps:
Step 1: Jar file download and import. Available through Download Center download Get jar; or install and import through maven warehouse. For details, refer to Installation method.
Step 2: get ID and Key. Need to Cloud Create an account and create an application in the "my app" section to obtain the App ID and App Key.
Step 3: when converting the cloud Excel document to PDF, you need to upload the Excel document in the "document management" section first.
Note: accounts created in the cloud can be tried for 10000 times and 2G document memory for free.

[example 1] convert local Excel document to PDF

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

import java.io.File;

public class ExcelToPDF {
    private static String appId = "App ID";
    private static String appKey = "App Key";

    public static void main(String[] args) throws ApiException{
        //Create a GeneralApi instance and configure account information
        GeneralApi generalApi = new GeneralApi(appId, appKey);
        //Configure related parameters
        String format = ExportFormat.PDF.toString();
        String inputFilePath = "test.xlsx";
        File data = new File(inputFilePath );
        String outputFilePath = "ToPDF.pdf";
        String password = null;

        //Call the putWorkbookConvert interface to save the document as PDF
        generalApi.putWorkbookConvert(format,outputFilePath,data, password);
    }
}

[example 2] convert the cloud Excel document to PDF

import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.api.WorkbookApi;
import spire.cloud.excel.sdk.model.ExportFormat;
import spire.cloud.excel.sdk.model.ExportOptions;

public class ExcelToPDF2 {
    private static String appId = "App ID";
    private static String appKey = "App Key";

    public static void main(String[] args)throws ApiException {
        //Create WorkbookApi instance and configure account information
        WorkbookApi workbookApi = new WorkbookApi(appId, appKey);

        //Configure related parameters
        String name= "test.xlsx";
        String outputFilePath = "ToPDF2.pdf";
        String format = ExportFormat.PDF.toString();
        ExportOptions options = null;
        String storage = null;
        String inputFolder = "input";
        String password = null;

        //Call the putWorkbookSaveAs interface to save the document as PDF
        workbookApi.putWorkbookSaveAs(name, outputFilePath, format, options, password, storage, inputFolder);
    }
}

The document conversion results can be viewed in the document management section, as follows:

Keywords: Java Excel SDK PCL

Added by Clinger on Wed, 11 Dec 2019 19:42:26 +0200