Skip to content

图片转PPT

注意:在学习使用不同函数之前,建议先阅读请求描述,了解基本的PDF处理流程。使用不同函数时,可以在上传文件时设置各自特殊的参数。其他基本步骤一致。

图片转PPT:

java
{
  "enableAiLayout": 1,
  "isContainImg": 1,
  "isContainAnnot": 1,
  "enableOcr": 0,
  "ocrLanguage": 8
}

所需参数

enableAiLayout:是否开启AI版面分析(0: 不开启;1: 开启)。默认 1。

isContainImg:转换时是否包含图像(0: 不开启;1: 开启)。默认 1。

isContainAnnot:转换时是否包含注释(0: 不开启;1: 开启)。默认 1。

enableOcr:是否使用OCR(0: 不开启;1: 开启)。默认 0。

ocrLanguage:OCR识别语种。1:CHINESE; 2:CHINESE_TRA; 3:ENGLISH; 4:KOREAN; 5:JAPANESE; 6:LATIN; 7:DEVANAGARI; 8:AUTO。默认 8。

Java示例

  1. 授权

    您需要将认证响应中的 替换为从控制台获取的 publicKeysecretKey,并使用 accessToken

    curl
    curl --location --request POST 'https://api-server.compdf.com/server/v1/oauth/token' \
    --header 'Content-Type: application/json' \
    --data-raw '{
       "publicKey": "publicKey",
       "secretKey": "secretKey"
    }'
    java
    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. 创建任务

    您需要将 替换为上一步获取的 accessToken,将 ***替换为所需的界面和任务错误消息语言类型。请求成功后,您将从响应中收到 taskId

    curl
    curl --location --request GET 'https://api-server.compdf.com/server/v1/task/img/pptx' \
    --header 'Authorization: Bearer accessToken'
    java
    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/img/pptx?language={{language}}")
          .method("GET", body)
          .addHeader("Authorization", "Bearer {{accessToken}}")
          .build();
        Response response = client.newCall(request).execute();
      }
    }
  3. 上传文件

    替换为您要转换的文件,将 替换为您上一步获取到的 taskId,将 替换为您需要的界面错误信息语言类型,将 替换为您第一步获取到的 accessToken

    curl
    curl --location --request POST 'https://api-server.compdf.com/server/v1/file/upload' \
    --header 'Authorization: Bearer accessToken' \
    --form 'file=@"test.png"' \
    --form 'taskId="taskId"' \
    --form 'password=""' \
    --form 'parameter="{   \"isAllowOcr\":1,\"isContainOcrBg\":0,\"isOnlyAiTable\":0}"' \
    --form 'language=""'
    java
    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}}")
          .addFormDataPart("language","{{language}}")
          .addFormDataPart("password","")
          .addFormDataPart("parameter","{  \"isAllowOcr\": 1 ,  \"isContainOcrBg\": 0}")
          .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. 执行任务

    替换为 创建任务 步骤中获取的 taskId,将 替换为第一步获取的 access_token,将 替换为所需的界面错误信息语言类型。

    curl
    curl --location -g --request GET 'https://api-server.compdf.com/server/v1/execute/start?taskId=taskId' \
    --header 'Authorization: Bearer accessToken'
    java
    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}}&language={{language}}")
         .method("GET", body)
         .addHeader("Authorization", "Bearer {{accessToken}}")
         .build();
       Response response = client.newCall(request).execute();
     }
    }
  5. 获取任务信息

    替换为 创建任务 步骤中获取的 taskId,将 替换为第一步中获取的 access_token

    curl
    curl --location -g --request GET 'https://api-server.compdf.com/server/v1/task/taskInfo?taskId=taskId' \
    --header 'Authorization: Bearer accessToken'
    java
    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();
      }
    }

结果

文件类型说明
.pptx完成后的 PowerPoint 文件