Spire.Cloud.PDF offers the PdfConvertApi interface to convert PDF to other document formats, such as DOC, DOCX, HTML, PCL, SVG, XPS and PNG. This tutorial will introduce how to use the interface to convert PDF to PNG.
import spire.cloud.pdf.sdk.ApiException;
import spire.cloud.pdf.sdk.Configuration;
import spire.cloud.pdf.sdk.api.PdfConvertApi;
public class PDFToImage {
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 PdfConvertApi object
static PdfConvertApi pdfConvertApi = new PdfConvertApi(configuration);
public static void main(String[] args) throws ApiException {
//Load the PDF sample
String name = "Sample.pdf";
//Specify the folder storing the sample, and it’s null if nothing
String folder = null;
//Use the 2G storage provided by E-iceblue Cloud, and it’s null by default
String storage = null;
//Specify the password of the sample, and it’s null if nothing
String password = null;
//Specify the resolution of the image
int dx = 300;
int dy = 300;
//Specify the storage path of the resulting document
String destFilepath = "output/";
//Call the convertToPng method to convert PDF to PNG
pdfConvertApi.convertToPng(name, destFilepath, dx, dy, folder, storage, password);
}
}
Output