OFD转换接口文档

5.3 OFD 转换

5.3.1 OFD转PDF

创建任务

POST https://api.iloveofd.cn/api/create
{
  "taskType": "OFD2PDF",
  "strPairs": {},
  "ossPendingFiles": [
    {
      "fileKey": "2642efca-cd38-46ec-bf3c-d1a2af8dea84.ofd",
      "fileName": "example.ofd"
    }
  ]
}

cURL

curl -X POST 'https://api.iloveofd.cn/api/create' \
  -H 'Content-Type: application/json' \
  -H 'token: your_token' \
  -d '{
    "taskType": "OFD2PDF",
    "strPairs": {},
    "ossPendingFiles": [
      {
        "fileKey": "2642efca-cd38-46ec-bf3c-d1a2af8dea84.ofd",
        "fileName": "example.ofd"
      }
    ]
  }'

Java

import okhttp3.*;

public class OfdToPdfExample {

    private static final String API_URL =
            "https://api.iloveofd.cn/api/create";

    public static void main(String[] args) throws Exception {

        OkHttpClient client = new OkHttpClient();

        String json = """
                {
                  "taskType": "OFD2PDF",
                  "strPairs": {},
                  "ossPendingFiles": [
                    {
                      "fileKey": "2642efca-cd38-46ec-bf3c-d1a2af8dea84.ofd",
                      "fileName": "example.ofd"
                    }
                  ]
                }
                """;

        RequestBody body = RequestBody.create(
                json,
                MediaType.parse("application/json")
        );

        Request request = new Request.Builder()
                .url(API_URL)
                .addHeader("token", "your_token")
                .post(body)
                .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

Python

import requests

url = "https://api.iloveofd.cn/api/create"

headers = {
    "token": "your_token",
    "Content-Type": "application/json"
}

data = {
    "taskType": "OFD2PDF",
    "strPairs": {},
    "ossPendingFiles": [
        {
            "fileKey": "2642efca-cd38-46ec-bf3c-d1a2af8dea84.ofd",
            "fileName": "example.ofd"
        }
    ]
}

response = requests.post(
    url,
    headers=headers,
    json=data
)

print(response.json())

5.3.2 OFD转Word

创建任务

POST https://api.iloveofd.cn/api/create
{
  "taskType": "OFD2WORD",
  "strPairs": { "device": "noocr"},
  "ossPendingFiles": [
    {
      "fileKey": "2642efca-cd38-46ec-bf3c-d1a2af8dea84.ofd",
      "fileName": "example.ofd"
    }
  ]
}
strPairs
文件文字能够复制,不启用ocr:"device": "noocr";
文件文字无法复制,启用ocr:"device": "ocr"。

5.3.3 OFD 转图片

将 OFD 文件转换为图片,支持设置图片清晰度,并可选择将生成的图片打包为 ZIP 文件。

请求

POST https://api.iloveofd.cn/api/create

请求 Header

参数 类型 必填 说明
token String 是 API 认证 Token
Content-Type String 是 application/json

请求参数

参数 类型 必填 说明
taskType String 是 固定为 OFD2Image
boolPairs Object 是 布尔类型参数
doublePairs Object 是 数值类型参数
ossPendingFiles Array 是 待转换的 OFD 文件

boolPairs

参数 类型 说明
zip Boolean 是否将生成的图片打包为 ZIP。true:打包;false:不打包

doublePairs

参数 类型 说明
quality Number 图片清晰度,对应不同的 PPI

quality 参数与 PPI 的对应关系:

quality PPI
12 20 PPI
15 72 PPI
20 150 PPI
25 300 PPI
30 600 PPI

ossPendingFiles

参数 类型 必填 说明
fileKey String 是 上传至 BOS 后的文件 Key
fileName String 是 原始文件名称

请求示例

{
  "taskType": "OFD2Image",
  "boolPairs": {
    "zip": true
  },
  "doublePairs": {
    "quality": 20
  },
  "ossPendingFiles": [
    {
      "fileKey": "2642efca-cd38-46ec-bf3c-d1a2af8dea84.ofd",
      "fileName": "example.ofd"
    }
  ]
}

参数说明

以上示例表示:

  • 将 example.ofd 转换为图片;
  • 图片清晰度设置为 150 PPI;
  • 将生成的图片打包为 ZIP 文件。

cURL

curl -X POST 'https://api.iloveofd.cn/api/create' \
  -H 'Content-Type: application/json' \
  -H 'token: your_token' \
  -d '{
    "taskType": "OFD2Image",
    "boolPairs": {
      "zip": true
    },
    "doublePairs": {
      "quality": 20
    },
    "ossPendingFiles": [
      {
        "fileKey": "2642efca-cd38-46ec-bf3c-d1a2af8dea84.ofd",
        "fileName": "example.ofd"
      }
    ]
  }'

Java

import okhttp3.*;

public class OfdToImageExample {

    private static final String API_URL =
            "https://api.iloveofd.cn/api/create";

    public static void main(String[] args) throws Exception {

        OkHttpClient client = new OkHttpClient();

        String json = """
                {
                  "taskType": "OFD2Image",
                  "boolPairs": {
                    "zip": true
                  },
                  "doublePairs": {
                    "quality": 20
                  },
                  "ossPendingFiles": [
                    {
                      "fileKey": "2642efca-cd38-46ec-bf3c-d1a2af8dea84.ofd",
                      "fileName": "example.ofd"
                    }
                  ]
                }
                """;

        RequestBody body = RequestBody.create(
                json,
                MediaType.parse("application/json")
        );

        Request request = new Request.Builder()
                .url(API_URL)
                .addHeader("Content-Type", "application/json")
                .addHeader("token", "your_token")
                .post(body)
                .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

Python

import requests

url = "https://api.iloveofd.cn/api/create"

headers = {
    "Content-Type": "application/json",
    "token": "your_token"
}

data = {
    "taskType": "OFD2Image",
    "boolPairs": {
        "zip": True
    },
    "doublePairs": {
        "quality": 20
    },
    "ossPendingFiles": [
        {
            "fileKey": "2642efca-cd38-46ec-bf3c-d1a2af8dea84.ofd",
            "fileName": "example.ofd"
        }
    ]
}

response = requests.post(
    url,
    headers=headers,
    json=data
)

print(response.json())

响应

创建任务成功后,接口返回 requestId,后续可使用该 ID 查询任务状态。

{
  "code": 200,
  "requestId": "c8d157af99e64296bd8e027060691e83"
}

使用以下接口查询任务处理状态:

GET https://api.iloveofd.cn/api/status/{requestId}

任务完成后,通过任务详情接口获取生成的图片或 ZIP 文件下载地址:

GET https://api.iloveofd.cn/api/detail/{requestId}

5.3.4 OFD 转长图

将 OFD 文件转换为长图,支持设置图片清晰度。

请求

POST https://api.iloveofd.cn/api/create

请求 Header

参数 类型 必填 说明
token String 是 API 认证 Token
Content-Type String 是 application/json

请求参数

参数 类型 必填 说明
taskType String 是 固定为 OFD2LongImage
doublePairs Object 是 数值类型参数
ossPendingFiles Array 是 待转换的 OFD 文件

doublePairs

参数 类型 说明
quality Number 图片清晰度,对应不同的 PPI

quality 参数与 PPI 的对应关系:

quality PPI
12 20 PPI
15 72 PPI
20 150 PPI
25 300 PPI
30 600 PPI

ossPendingFiles

参数 类型 必填 说明
fileKey String 是 上传至 BOS 后的文件 Key
fileName String 是 原始文件名称

请求示例

{
  "taskType": "OFD2LongImage",
  "doublePairs": {
    "quality": 20
  },
  "ossPendingFiles": [
    {
      "fileKey": "2642efca-cd38-46ec-bf3c-d1a2af8dea84.ofd",
      "fileName": "example.ofd"
    }
  ]
}

参数说明

以上示例表示:

  • 将 example.ofd 转换为图片;
  • 图片清晰度设置为 150 PPI;

cURL

curl -X POST 'https://api.iloveofd.cn/api/create' \
  -H 'Content-Type: application/json' \
  -H 'token: your_token' \
  -d '{
    "taskType": "OFD2LongImage",
    "doublePairs": {
      "quality": 20
    },
    "ossPendingFiles": [
      {
        "fileKey": "2642efca-cd38-46ec-bf3c-d1a2af8dea84.ofd",
        "fileName": "example.ofd"
      }
    ]
  }'

Java

import okhttp3.*;

public class OfdToImageExample {

    private static final String API_URL =
            "https://api.iloveofd.cn/api/create";

    public static void main(String[] args) throws Exception {

        OkHttpClient client = new OkHttpClient();

        String json = """
                {
                  "taskType": "OFD2LongImage",
                  "doublePairs": {
                    "quality": 20
                  },
                  "ossPendingFiles": [
                    {
                      "fileKey": "2642efca-cd38-46ec-bf3c-d1a2af8dea84.ofd",
                      "fileName": "example.ofd"
                    }
                  ]
                }
                """;

        RequestBody body = RequestBody.create(
                json,
                MediaType.parse("application/json")
        );

        Request request = new Request.Builder()
                .url(API_URL)
                .addHeader("Content-Type", "application/json")
                .addHeader("token", "your_token")
                .post(body)
                .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

Python

import requests

url = "https://api.iloveofd.cn/api/create"

headers = {
    "Content-Type": "application/json",
    "token": "your_token"
}

data = {
    "taskType": "OFD2LongImage",
    "doublePairs": {
        "quality": 20
    },
    "ossPendingFiles": [
        {
            "fileKey": "2642efca-cd38-46ec-bf3c-d1a2af8dea84.ofd",
            "fileName": "example.ofd"
        }
    ]
}

response = requests.post(
    url,
    headers=headers,
    json=data
)

print(response.json())

响应

创建任务成功后,接口返回 requestId,后续可使用该 ID 查询任务状态。

{
  "code": 200,
  "requestId": "c8d157af99e64296bd8e027060691e83"
}

使用以下接口查询任务处理状态:

GET https://api.iloveofd.cn/api/status/{requestId}

任务完成后,通过任务详情接口获取生成的图片或 ZIP 文件下载地址:

GET https://api.iloveofd.cn/api/detail/{requestId}

5.3.5 OFD 合并

将多个 OFD 文件按照指定顺序合并为一个 OFD 文件。

请求

POST https://api.iloveofd.cn/api/create

请求 Header

参数 类型 必填 说明
token String 是 API 认证 Token
Content-Type String 是 固定为 application/json

请求参数

参数 类型 必填 说明
taskType String 是 固定为 OFDMerge
intPairs Object 是 指定文件的合并顺序
ossPendingFiles Array 是 待合并的 OFD 文件

intPairs

intPairs 用于指定各 OFD 文件的合并顺序。

  • Key:OFD 文件的 fileKey
  • Value:文件的合并顺序,从 0 开始递增
  • intPairs 中的 Key 必须与 ossPendingFiles 中的 fileKey 对应

例如:

{
  "intPairs": {
    "file-a.ofd": 0,
    "file-b.ofd": 1,
    "file-c.ofd": 2
  }
}

表示按照以下顺序合并:

file-a.ofd → file-b.ofd → file-c.ofd

ossPendingFiles

参数 类型 必填 说明
fileKey String 是 上传至 BOS 后的文件 Key
fileName String 是 原始文件名称

请求示例

{
  "taskType": "OFDMerge",
  "intPairs": {
    "3036d708-66e6-4cc3-9cc4-e163d0bf4996.ofd": 0,
    "c4f2cfb0-d0fe-429a-a310-1aeaf84d0f29.ofd": 1,
    "030a2b73-d21d-43f1-9018-535c9e15aa16.ofd": 2
  },
  "ossPendingFiles": [
    {
      "fileName": "6e9fbd10-7e07-4269-b7ea-c42b1550a448.ofd",
      "fileKey": "3036d708-66e6-4cc3-9cc4-e163d0bf4996.ofd"
    },
    {
      "fileName": "369d567d-2937-4faf-a0c7-e79d31b33495.ofd",
      "fileKey": "030a2b73-d21d-43f1-9018-535c9e15aa16.ofd"
    },
    {
      "fileName": "b491ad45-4db9-4b2a-9b97-c6e51573d2ca.ofd",
      "fileKey": "c4f2cfb0-d0fe-429a-a310-1aeaf84d0f29.ofd"
    }
  ]
}

参数说明

以上示例表示将 3 个 OFD 文件合并为一个文件,合并顺序为:

6e9fbd10-7e07-4269-b7ea-c42b1550a448.ofd
        ↓
b491ad45-4db9-4b2a-9b97-c6e51573d2ca.ofd
        ↓
369d567d-2937-4faf-a0c7-e79d31b33495.ofd

对应的顺序由 intPairs 中的 Value 决定:

0 → 3036d708-66e6-4cc3-9cc4-e163d0bf4996.ofd
1 → c4f2cfb0-d0fe-429a-a310-1aeaf84d0f29.ofd
2 → 030a2b73-d21d-43f1-9018-535c9e15aa16.ofd

cURL

curl -X POST 'https://api.iloveofd.cn/api/create' \
  -H 'Content-Type: application/json' \
  -H 'token: your_token' \
  -d '{
    "taskType": "OFDMerge",
    "intPairs": {
      "3036d708-66e6-4cc3-9cc4-e163d0bf4996.ofd": 0,
      "c4f2cfb0-d0fe-429a-a310-1aeaf84d0f29.ofd": 1,
      "030a2b73-d21d-43f1-9018-535c9e15aa16.ofd": 2
    },
    "ossPendingFiles": [
      {
        "fileName": "6e9fbd10-7e07-4269-b7ea-c42b1550a448.ofd",
        "fileKey": "3036d708-66e6-4cc3-9cc4-e163d0bf4996.ofd"
      },
      {
        "fileName": "369d567d-2937-4faf-a0c7-e79d31b33495.ofd",
        "fileKey": "030a2b73-d21d-43f1-9018-535c9e15aa16.ofd"
      },
      {
        "fileName": "b491ad45-4db9-4b2a-9b97-c6e51573d2ca.ofd",
        "fileKey": "c4f2cfb0-d0fe-429a-a310-1aeaf84d0f29.ofd"
      }
    ]
  }'

Java

import okhttp3.*;

public class OfdMergeExample {

    private static final String API_URL =
            "https://api.iloveofd.cn/api/create";

    public static void main(String[] args) throws Exception {

        OkHttpClient client = new OkHttpClient();

        String json = """
                {
                  "taskType": "OFDMerge",
                  "intPairs": {
                    "3036d708-66e6-4cc3-9cc4-e163d0bf4996.ofd": 0,
                    "c4f2cfb0-d0fe-429a-a310-1aeaf84d0f29.ofd": 1,
                    "030a2b73-d21d-43f1-9018-535c9e15aa16.ofd": 2
                  },
                  "ossPendingFiles": [
                    {
                      "fileName": "6e9fbd10-7e07-4269-b7ea-c42b1550a448.ofd",
                      "fileKey": "3036d708-66e6-4cc3-9cc4-e163d0bf4996.ofd"
                    },
                    {
                      "fileName": "369d567d-2937-4faf-a0c7-e79d31b33495.ofd",
                      "fileKey": "030a2b73-d21d-43f1-9018-535c9e15aa16.ofd"
                    },
                    {
                      "fileName": "b491ad45-4db9-4b2a-9b97-c6e51573d2ca.ofd",
                      "fileKey": "c4f2cfb0-d0fe-429a-a310-1aeaf84d0f29.ofd"
                    }
                  ]
                }
                """;

        RequestBody body = RequestBody.create(
                json,
                MediaType.parse("application/json")
        );

        Request request = new Request.Builder()
                .url(API_URL)
                .addHeader("Content-Type", "application/json")
                .addHeader("token", "your_token")
                .post(body)
                .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

Python

import requests

url = "https://api.iloveofd.cn/api/create"

headers = {
    "Content-Type": "application/json",
    "token": "your_token"
}

data = {
    "taskType": "OFDMerge",
    "intPairs": {
        "3036d708-66e6-4cc3-9cc4-e163d0bf4996.ofd": 0,
        "c4f2cfb0-d0fe-429a-a310-1aeaf84d0f29.ofd": 1,
        "030a2b73-d21d-43f1-9018-535c9e15aa16.ofd": 2
    },
    "ossPendingFiles": [
        {
            "fileName": "6e9fbd10-7e07-4269-b7ea-c42b1550a448.ofd",
            "fileKey": "3036d708-66e6-4cc3-9cc4-e163d0bf4996.ofd"
        },
        {
            "fileName": "369d567d-2937-4faf-a0c7-e79d31b33495.ofd",
            "fileKey": "030a2b73-d21d-43f1-9018-535c9e15aa16.ofd"
        },
        {
            "fileName": "b491ad45-4db9-4b2a-9b97-c6e51573d2ca.ofd",
            "fileKey": "c4f2cfb0-d0fe-429a-a310-1aeaf84d0f29.ofd"
        }
    ]
}

response = requests.post(
    url,
    headers=headers,
    json=data
)

print(response.json())

响应

创建任务成功后,接口返回 requestId。开发者可使用该 ID 查询任务处理状态。

{
  "code": 200,
  "requestId": "c8d157af99e64296bd8e027060691e83"
}

使用 requestId 查询任务状态:

GET https://api.iloveofd.cn/api/status/{requestId}

任务完成后,通过任务详情接口获取合并后的 OFD 文件下载地址:

GET https://api.iloveofd.cn/api/detail/{requestId}