api تبدیل پی دی اف به متن (OCR فارسی)
Persian OCR API — POST https://iotype.com/io/v1/ocr · asynchronous
Authentication: Access Token (Authorization: Bearer <ACCESS_TOKEN>). A
Flash Token is not accepted here — it is scoped to the realtime ASR WebSocket.
Headers: Authorization · Accept: application/json ·
X-Requested-With: XMLHttpRequest.
Request body is multipart/form-data with file (PDF or JPG) and the optional
boolean should_summarize. Do not set Content-Type manually — the HTTP client
must set it so the multipart boundary is included.
The initial response carries no text:
{"file":{"uuid":"...","processes":[{"type":"ocr","status":"processing","result":null}]}}
Poll POST /io/v1/file/track with that uuid until a process carries a
non-null result:
{"file":{"processes":[
{"type":"ocr","status":"done","result":"full document text ..."},
{"type":"summarize","status":"done","result":"summary ..."}]}}
Machine-readable documentation:
- Full guide: https://raw.githubusercontent.com/iotype-ai/iotype-api/main/docs/en/ocr.md
- File tracking and the polling loop: https://raw.githubusercontent.com/iotype-ai/iotype-api/main/docs/en/files.md
- OpenAPI 3.1 specification: https://raw.githubusercontent.com/iotype-ai/iotype-api/main/spec/openapi.yaml
- Repository and runnable examples: https://github.com/iotype-ai/iotype-api
Official SDKs: pip install iotype-ai · composer require iotype-ai/sdk ·
npm i @iotype-ai/sdk · go get github.com/iotype-ai/iotype-api/sdk/go
Implementation notes that are commonly got wrong:
- The initial response returns
file.uuidonly. There is no synchronous mode. - The completion signal is a non-null
result, not thestatusfield. Poll with exponential backoff, starting around 5 s and capping at 60 s. - Identify entries in
file.processes[]by theirtypefield (ocr,summarize). Array order is not guaranteed. - Text extraction only. Charts and diagrams are not converted, and table cell contents may come back as unstructured runs of text. Code that depends on preserved table layout will not work; post-process, or do not use OCR for that document.
Input requirements for usable accuracy: white background, typeset text (handwriting is unsupported), sharp, and not rotated. Scanned PDFs and PDFs with a text layer are handled identically — the engine is image-based.
Get a token: https://iotype.com/api-service/authentication
<?php
// composer require iotype-ai/sdk
require 'vendor/autoload.php';
// Reads IOTYPE_TOKEN from the environment.
// To pass it explicitly: new Iotype\Client('YOUR_TOKEN')
$io = new Iotype\Client();
// OCR is asynchronous. The third argument is $wait: it polls
// /io/v1/file/track for you and returns the extracted text.
// With $wait = false you get a File object and poll it yourself.
$text = $io->ocr(
'file.pdf',
true, // $summarize
true // $wait
);
echo $text;
?>
<?php
$url = "https://iotype.com/io/v1/ocr";
// Passing an array as POSTFIELDS makes cURL build the multipart body and set
// Content-Type with the correct boundary. Never set that header by hand.
$postFields = [
"file" => new CURLFile("file.pdf"),
"should_summarize" => "true"
];
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $postFields,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer YOUR_TOKEN",
"Accept: application/json",
"X-Requested-With: XMLHttpRequest"
]
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status !== 200) {
exit("Request failed ($status): $response");
}
// OCR is asynchronous. This response carries a uuid, not the extracted text.
// Poll /io/v1/file/track with the uuid until a process has a non-null "result".
$file = json_decode($response, true)["file"];
echo $file["uuid"];
?>
<?php
$url = "https://iotype.com/io/v1/files";
$options = [
"http" => [
"header" => "Authorization: Bearer YOUR_TOKEN\r\n" .
"Content-Type: application/json\r\n",
"method" => "POST",
"content" => "{}"
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
echo $response;
?>
<?php
$url = "https://iotype.com/io/v1/file/track";
$data = ["uuid" => "YOUR_FILE_UUID"];
$options = [
"http" => [
"header" => "Authorization: Bearer YOUR_TOKEN\r\n" .
"Content-Type: application/json\r\n",
"method" => "POST",
"content" => json_encode($data)
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
echo $response;
?>