PDF Merge 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 Merge:
- In the same task, upload multiple files (up to five). If
pageOptions
is not provided, it will merge multiple files. - In the same task, upload multiple files (up to five). If
pageOptions
is provided, it will merge the specified pages of multiple files.
java
{
"pageOptions": "['1,2']"
}
Required Parameters:
pageOptions
: Page range of the merged documents, starting from 1. For example: 1,2,4,6,9-11
(if not provided, all pages are included by default; the provided page numbers cannot exceed the maximum page number of the document).
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.
java
import java.io.*;
import okhttp3.*;
public class Main {
public static void main(String[] args) throws IOException {
List<File> filesToUpload = List.of(
new File("file1.pdf"),
new File("file2.pdf"),
new File("file3.pdf")
);
OkHttpClient client = new OkHttpClient().newBuilder().build();
MultipartBody.Builder bodyBuilder = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("language", "{{language}}")
.addFormDataPart("password", "")
.addFormDataPart("parameter", "{\"pageOptions\": \"['1,2']\"}");
for (File file : filesToUpload) {
bodyBuilder.addFormDataPart(
"file",
file.getName(),
RequestBody.create(
MediaType.parse("application/octet-stream"),
file
)
);
}
Request request = new Request.Builder()
.url("https://api-server.compdf.com/server/v1/process/pdf/merge")
.method("POST", bodyBuilder.build())
.addHeader("x-api-key", "{{apiKey}}")
.build();
Response response = client.newCall(request).execute();
}
}
Result:
File Type | Description |
---|---|
Merged PDF file |