Document Analysis
Output .TXT format file
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 TXT:
{
"enableAiLayout": 1,
"enableOcr": 0,
"ocrRecognitionLang": "AUTO",
"pageRanges": "1,2,3-5",
"txtTableFormat": 1
}Required parameters
enableAiLayout: Whether to enable AI layout analysis (0: not enabled; 1: enabled). Default 1.
enableOcr: whether to use OCR (0: not enabled; 1: enabled). Default is 0.
ocrLanguage: OCR recognition language,supported types and definitions: AUTO: Automatic, CHINESE: Simplified Chinese, CHINESE_TRAD: Traditional Chinese, ENGLISH: English, KOREAN: Korean, JAPANESE: Japanese, LATIN: Latin, DEVANAGARI: Devanagari, CYRILLIC: Cyrillic, ARABIC: Arabic, TAMIL: Tamil, TELUGU: Telugu, KANNADA: Kannada, THAI: Thai, GREEK: Greek, ESLAV: Slavic languages. Default is AUTO.
pageRanges: specify page number conversion, starting from 1. Default is empty.
txtTableFormat: whether to format the table when converting pdf to txt (0: not enabled; 1: enabled). Default is 1.
Request 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","")
.build();
Request request = new Request.Builder()
.url("https://api-server.compdf.com/server/v2/process/pdf/txt")
.method("POST", body)
.addHeader("x-api-key", "{{apiKey}}")
.build();
Response response = client.newCall(request).execute();
}
}Result:
| File Type | Description |
|---|---|
| .txt | Converted TXT file |
| File Type | Description |
|---|---|
| .txt | The TXT file after the transfer process is completed |