PDF to PNG Tool Guide
Note:Before learning how to use different functions, we recommend that read the Request Workflow to know a basic PDF processing process. When using different functions, you can set their own special parameters when uploading files. Other basic steps are consistent.
PDF to JPG:
{
"pageRanges": "1,2,3-5",
"imageColorMode": "e_Color",
"imageScaling": "1.0"
}
Required parameters
pageRanges
: Specify page number conversion, starting from 1. Default is empty.
imageColorMode
: Specifies the image color mode of the image file. e_Color: color mode; e_Gray: grayscale mode; e_Binary: black and white mode. The default is e_Color.
imageScaling
: Specifies the image scaling ratio of the image file. Default is 1.0.
Setting Image Color Modes
Supported image color modes in ComPDFKit Conversion SDK include:
Color
: Color mode, where the image effect is consistent with the original PDF page.
Gray
: Grayscale mode.
Binary
: Black and white mode, which applies binarization to the original effect.
Setting Image Scaling
The SDK supports setting image scaling. The default scaling is 1.0, which maintains the original PDF page size. If you want to double the image size, you can set ImageScaling
to 2.0; similarly, to reduce the image size by half, set ImageScaling
to 0.5.
Java Example:
Replace apiKey with the publicKey obtained from the dashboard, file with the file you want to convert, and language with your preferred interface error prompt language type.
import java.io.*;
import okhttp3.*;
public class main {
public static void main(String []args) throws IOException{
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("file","{{file}}",
RequestBody.create(MediaType.parse("application/octet-stream"),
new File("<file>")))
.addFormDataPart("language","{{language}}")
.addFormDataPart("password","")
.addFormDataPart("parameter","{ \"imageScaling\": \"1.0\"}")
.build();
Request request = new Request.Builder()
.url("https://api-server.compdf.com/server/v1/process/pdf/png")
.method("POST", body)
.addHeader("x-api-key", "{{apiKey}}")
.build();
Response response = client.newCall(request).execute();
}
}
Result:
File Type | Description |
---|---|
.zip | The image file zip after the transfer process is completed |