I introduced how to use the ConvertPptToPath method provided by the DocumentApi interface to convert a whole PowerPoint document to PDF in the previous article. Now I’ll use the SplitPpt method to convert specified presentation slides to several images in .png format.
The following is a PowerPoint document including four slides, and now I'll use Java codes to convert the last three slides to three images.
import spire.cloud.powerpoint.sdk.ApiException;
import spire.cloud.powerpoint.sdk.Configuration;
import spire.cloud.powerpoint.sdk.api.DocumentApi;
import spire.cloud.powerpoint.sdk.model.ExportOptions;
import spire.cloud.powerpoint.sdk.model.SlideExportFormat;
public class PPTToPNG {
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a configuration object based on your App ID and App Key
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Initialize the DocumentApi object
static DocumentApi documentApi = new DocumentApi(configuration);
public static void main(String[] args) throws ApiException {
//Load a PowerPoint document
String name = "Sample.pptx";
//Specify the password used to open the sample, and it's null if nothing
String password = null;
//Use the 2G storage provided by E-iceblue Cloud, and it’s null by default
String storage = null;
//Specify the folder storing the sample, and it’s null if nothing
String folder = "input";
//Set the ExportOptions as null
ExportOptions options = null;
//Specify the document format as PNG
String format = SlideExportFormat.PNG.toString();
//Set the size of images
Integer width = Math.round(72*33.867f*0.3937f);
Integer height = Math.round(72*19.05f*0.3937f);
//Specify the range of slides which will be converted to images(From 0 on)
Integer from = 1;
Integer to = 3;
//Specify the output folder of the resulting file
String destFolder ="output" ;
//Run the splitPpt method to convert specified range of slides to images
documentApi.splitPpt(name, options, format, width, height, to, from, destFolder, password, storage, folder);
}
}
Output