|
// for more examples, please visit https://github.com/aspose-html-cloud/aspose-html-cloud-java |
|
|
|
try |
|
{ |
|
// Get ClientID and ClientSecret from https://dashboard.aspose.cloud/ |
|
String clientId = "bbf94a2c-6d7e-4020-b4d2-b9809741374e"; |
|
String clientSecret = "1c9379bb7d701c26cc87e741a29987bb"; |
|
|
|
// details for Api invocation |
|
com.aspose.html.Configuration.setAPP_SID(clientId); |
|
com.aspose.html.Configuration.setAPI_KEY(clientSecret); |
|
com.aspose.html.Configuration.setBasePath("https://api.aspose.cloud/v3.0"); |
|
com.aspose.html.Configuration.setAuthPath("https://api.aspose.cloud/connect/token"); |
|
com.aspose.html.Configuration.setUserAgent("WebKit"); |
|
com.aspose.html.Configuration.setDebug(true); |
|
|
|
// Create an object of Aspose.HTML Cloud API |
|
com.aspose.html.api.ConversionApi htmlApi = new ApiClient().createService(ConversionApi.class); |
|
|
|
// The html document from cloud storage |
|
String name = "list.html"; |
|
// resultant image format |
|
String outFormat = "PNG"; |
|
|
|
Integer width = 800; // Resulting image width. |
|
Integer height = 1000; // Resulting image height. |
|
Integer leftMargin = 10; // Left resulting image margin. |
|
Integer rightMargin = 10; // Right resulting image margin. |
|
Integer topMargin = 10; // Top resulting image margin. |
|
Integer bottomMargin = 10; // Bottom resulting image margin. |
|
Integer resolution = 300; // Resolution of resulting image. |
|
String folder = null; // The folder in the storage. Should exist. |
|
String storage = "Internal"; // Name of the storage. null |
|
|
|
// Invoke the API for HTMl to JPG conversion |
|
retrofit2.Call<okhttp3.ResponseBody> call = htmlApi.GetConvertDocumentToImage(name, outFormat, width, height, leftMargin, rightMargin, topMargin, bottomMargin, resolution, folder, storage); |
|
|
|
// (optional custom method to save resultant JPG to local drive) |
|
checkAndSave(call, "resultantFile.png"); |
|
|
|
System.out.println("HTML to JPG conversion sucessfull !"); |
|
}catch(Exception ex) |
|
{ |
|
System.out.println(ex); |
|
} |