Documentation

In addition to simple PDF format conversion, we provide more parameter choices for advanced functions. You can set the parameters you want in the process of upload file . Below you can learn about the optional parameters of various functions.

Simple PDF Conversion Tool Guides

Note:Before learning how to use advanced functions, we recommend that you read the Request workflow to understand a basic PDF processing process.

Java Example

  1. Authentication

    You need to replace {{public_key}} and {{secret_key}} with accessToken in the publicKey and secretKey authentication getback values you get from the console.

    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 = RequestBody.create(mediaType, "{\n    \"publicKey\": \"{{public_key}}\",\n    \"secretKey\": \"{{secret_key}}\"\n}");
        Request request = new Request.Builder()
          .url("https://api-server.compdf.com/server/v1/oauth/token")
          .method("POST", body)
          .build();
        Response response = client.newCall(request).execute();
      }
    }
    
  2. Create Task

    You need to replace {{accessToken}} with the accessToken obtained from the previous step, and {{executeTypeUrl}} with the conversion type you need. You can get the function you want to use in the Tools, and get the taskId in the return value after success.

    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 = RequestBody.create(mediaType, "");
        Request request = new Request.Builder()
          .url("https://api-server.compdf.com/server/v1/task/{{executeTypeUrl}}")
          .method("GET", body)
          .addHeader("Authorization", "Bearer {{accessToken}}")
          .build();
        Response response = client.newCall(request).execute();
      }
    }
    
  3. Upload Files

    Replace {{file}} with the file you want to convert, {{taskId}} with the taskId obtained in the previous step, and {{accessToken}} with the accessToken obtained in the first step.

    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("taskId","{{taskId}}")
          // your file hava password
          //.addFormDataPart("password","{{password}}")
          .addFormDataPart("parameter","<parameter>")
          .build();
        Request request = new Request.Builder()
          .url("https://api-server.compdf.com/server/v1/file/upload")
          .method("POST", body)
          .addHeader("Authorization", "Bearer {{accessToken}}")
          .build();
        Response response = client.newCall(request).execute();
      }
    }
    
  4. Process Files

    Replace {{taskId}} with the taskId you obtained from the Create task, and {{accessToken}} with the accessToken obtained in the first step.

    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 = RequestBody.create(mediaType, "");
       Request request = new Request.Builder()
         .url("https://api-server.compdf.com/server/v1/execute/start?taskId={{taskId}}")
         .method("GET", body)
         .addHeader("Authorization", "Bearer {{accessToken}}")
         .build();
       Response response = client.newCall(request).execute();
     }
    }
    
  5. Get Task Information

    Replace {{taskId}} with you from Create the task obtained in the taskId, {{access_token}} replaced by access_token obtained in the first step .

    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 = RequestBody.create(mediaType, "");
        Request request = new Request.Builder()
          .url("https://api-server.compdf.com/server/v1/task/taskInfo?taskId={{taskId}}")
          .method("GET", body)
          .addHeader("Authorization", "Bearer {{accessToken}}")
          .build();
        Response response = client.newCall(request).execute();
      }
    }