How to convert PDF to image in Java using Cloud API (low level)

  • Home
  • /
  • Articles
  • /
  • How to convert PDF to image in Java using Cloud API (low level)

This code sample will show how to convert PDF to image in Java using Cloud API (low level). You can set such parameters as image resolution, quality, and image output format.

You may also find useful to check how to extract data from a PDF document to CSV.

PDF to JPEG

POST/GET endpoint:

https://bytescout.io/v1/pdf/convert/to/jpg

Code Sample:

import Bytescout\Client\API.*;
import Bytescout\Client\API.auth.*;
import Bytescout\Client\API.model.*;
import Bytescout\Client\API.api.DefaultApi;

import java.io.File;
import java.util.*;

public class DefaultApiExample {

    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        
        // Configure API key authorization: api_key
        ApiKeyAuth api_key = (ApiKeyAuth) defaultClient.getAuthentication("api_key");
        api_key.setApiKey("YOUR API KEY");
        // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
        //api_key.setApiKeyPrefix("Token");

        DefaultApi apiInstance = new DefaultApi();
        String pages = pages_example; // String | Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'.
        String name = name_example; // String | File name for generated result.
        String url = url_example; // String | URL of the source PDF file.
        try {
            MultiResponseModel result = apiInstance.pdfConvertToJpgPost(pages, name, url);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling DefaultApi#pdfConvertToJpgPost");
            e.printStackTrace();
        }
    }
}

PDF to PNG

POST/GET endpoint:

https://bytescout.io/v1/pdf/convert/to/png

Code Sample (PDF to PNG):

import Bytescout\Client\API.*;
import Bytescout\Client\API.auth.*;
import Bytescout\Client\API.model.*;
import Bytescout\Client\API.api.DefaultApi;

import java.io.File;
import java.util.*;

public class DefaultApiExample {

    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        
        // Configure API key authorization: api_key
        ApiKeyAuth api_key = (ApiKeyAuth) defaultClient.getAuthentication("api_key");
        api_key.setApiKey("YOUR API KEY");
        // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
        //api_key.setApiKeyPrefix("Token");

        DefaultApi apiInstance = new DefaultApi();
        String pages = pages_example; // String | Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'.
        String name = name_example; // String | File name for generated result.
        String url = url_example; // String | URL of the source PDF file.
        try {
            MultiResponseModel result = apiInstance.pdfConvertToPngPost(pages, name, url);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling DefaultApi#pdfConvertToPngPost");
            e.printStackTrace();
        }
    }
}

PDF to TIFF

POST/GET endpoint:

https://bytescout.io/v1/pdf/convert/to/tiff

Code Sample (PDF to TIFF):

import Bytescout\Client\API.*;
import Bytescout\Client\API.auth.*;
import Bytescout\Client\API.model.*;
import Bytescout\Client\API.api.DefaultApi;

import java.io.File;
import java.util.*;

public class DefaultApiExample {

    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        
        // Configure API key authorization: api_key
        ApiKeyAuth api_key = (ApiKeyAuth) defaultClient.getAuthentication("api_key");
        api_key.setApiKey("YOUR API KEY");
        // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
        //api_key.setApiKeyPrefix("Token");

        DefaultApi apiInstance = new DefaultApi();
        String pages = pages_example; // String | Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'.
        String name = name_example; // String | File name for generated result.
        String url = url_example; // String | URL of the source PDF file.
        try {
            SingleResponseModel result = apiInstance.pdfConvertToTiffPost(pages, name, url);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling DefaultApi#pdfConvertToTiffPost");
            e.printStackTrace();
        }
    }
}
prev
next