Document to Text Converter

Convert PDFs and Images to Text

Drag & drop your PDF file here, or click to select

(Only .pdf files are accepted)

API Documentation

Integrate our document processing service into your PHP applications using these RESTful API endpoints.

Base URL: http://your-domain.com

Developer Links (Postman)

Use these links to view the API in the browser or import the OpenAPI spec into Postman.

OpenAPI JSON
/openapi.json

Import in Postman: APIs → Import → Link

Swagger UI
/docs

Try endpoints interactively in the browser

POST /upload-pdf/

Convert PDF documents to plain text with preserved formatting.

Request Parameters

Parameter Type Required Description
file File Yes PDF file to be processed (max 10MB)

Response

Success Response (200 OK):

{
    "message": "PDF processed successfully",
    "extracted_text": "The text content of the PDF...",
    "pages": [
        { "page": 1, "text": "Page 1 text..." },
        { "page": 2, "text": "Page 2 text..." }
    ],
    "download_link_txt": "/download/document.txt",
    "download_link_json": "/download/document.json"
}

Error Response (4xx/5xx):

{
    "detail": "Error message describing the issue"
}

PHP Example

// Set your API endpoint
$apiUrl = 'http://your-domain.com/upload-pdf/';
$pdfFilePath = '/path/to/your/document.pdf';

// Prepare the file for upload
$cfile = new CURLFile(
    $pdfFilePath,
    'application/pdf',
    basename($pdfFilePath)
);

// Initialize cURL session
$ch = curl_init();

// Set cURL options
curl_setopt_array($ch, [
    CURLOPT_URL => $apiUrl,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => ['file' => $cfile],
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Accept: application/json',
    ],
]);

// Execute the request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

// Process the response
if ($httpCode === 200) {
    $result = json_decode($response, true);
    
    // Save the extracted text to a file
    file_put_contents('extracted_text.txt', $result['extracted_text']);
    
    // Download the processed JSON output
    $downloadUrl = 'http://your-domain.com' . $result['download_link_json'];
    $fileContent = file_get_contents($downloadUrl);
    file_put_contents('downloaded_output.json', $fileContent);
    
    echo "Processing complete!\n";
    echo "- Extracted text saved to: extracted_text.txt\n";
    echo "- Downloaded file saved to: downloaded_output.json\n";
} else {
    $errorData = json_decode($response, true);
    echo "Error [$httpCode]: " . ($errorData['detail'] ?? 'Unknown error occurred') . "\n";
    if ($error) {
        echo "cURL Error: $error\n";
    }
}

cURL Example

curl -X POST \
  'http://your-domain.com/upload-pdf/' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@/path/to/your/document.pdf;type=application/pdf'
POST /upload-image/

Extract text from images using OCR (Optical Character Recognition). Supports multiple image formats.

Request Parameters

Parameter Type Required Description
file File Yes Image file (PNG, JPG, JPEG, BMP, TIFF) to process (max 10MB)

Response

Success Response (200 OK):

{
    "message": "Image processed successfully",
    "extracted_text": "The extracted text from the image...",
    "download_link_txt": "/download/extracted_text.txt",
    "download_link_json": "/download/extracted_text.json"
}

PHP Example

// Set your API endpoint
$apiUrl = 'http://your-domain.com/upload-image/';
$imagePath = '/path/to/your/image.jpg';

// Get the MIME type of the image
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimeType = finfo_file($finfo, $imagePath);
finfo_close($finfo);

// Prepare the file for upload
$cfile = new CURLFile($imagePath, $mimeType, basename($imagePath));

// Initialize cURL session
$ch = curl_init();

// Set cURL options
curl_setopt_array($ch, [
    CURLOPT_URL => $apiUrl,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => ['file' => $cfile],
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Accept: application/json',
    ],
]);

// Execute the request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

// Process the response
if ($httpCode === 200) {
    $result = json_decode($response, true);
    
    // Save the extracted text to a file
    file_put_contents('ocr_output.txt', $result['extracted_text']);
    
    // Download the processed JSON output
    $downloadUrl = 'http://your-domain.com' . $result['download_link_json'];
    $fileContent = file_get_contents($downloadUrl);
    file_put_contents('downloaded_ocr.json', $fileContent);
    
    echo "OCR processing complete!\n";
    echo "- Extracted text saved to: ocr_output.txt\n";
    echo "- Downloaded file saved to: downloaded_ocr.json\n";
} else {
    $errorData = json_decode($response, true);
    echo "Error [$httpCode]: " . ($errorData['detail'] ?? 'Failed to process image') . "\n";
    if ($error) {
        echo "cURL Error: $error\n";
    }
}

cURL Example

curl -X POST \
  'http://your-domain.com/upload-image/' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@/path/to/your/image.jpg;type=image/jpeg'
GET /download/{filename}

Download previously converted output files using the provided download link (supports .txt and .json).

URL Parameters

Parameter Type Required Description
filename String Yes Name of the file to download (as provided in the upload response)

PHP Example

// The download URL received from the upload response
$downloadUrl = 'http://your-domain.com/download/filename.json';
$savePath = 'downloaded_file.json';

// Method 1: Using file_get_contents (simpler)
try {
    $content = file_get_contents($downloadUrl);
    if ($content !== false) {
        file_put_contents($savePath, $content);
        echo "File downloaded successfully to: $savePath\n";
    } else {
        throw new Exception("Failed to download file");
    }
} catch (Exception $e) {
    echo "Error downloading file: " . $e->getMessage() . "\n";
}

// Method 2: Using cURL (more control)
$ch = curl_init($downloadUrl);
$fp = fopen($savePath, 'w+');

curl_setopt_array($ch, [
    CURLOPT_FILE => $fp,
    CURLOPT_HEADER => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_SSL_VERIFYPEER => false, // Only for testing, remove in production
]);

$success = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);

curl_close($ch);
fclose($fp);

if ($success && $httpCode === 200) {
    echo "File downloaded successfully to: $savePath\n";
} else {
    unlink($savePath); // Remove the empty/incomplete file
    echo "Failed to download file. HTTP Code: $httpCode\n";
    if ($error) {
        echo "cURL Error: $error\n";
    }
}