Convert PDF, Word, Excel, and Image files to Text
Drag & drop your file here, or click to select
(Supports: .pdf, .doc, .docx, .xls, .xlsx, .png, .jpg, .jpeg)
File processed successfully!
An error occurred while processing your file.
Integrate our document processing service into your PHP applications using these RESTful API endpoints.
Base URL: http://your-domain.com
Use these links to view the API in the browser or import the OpenAPI spec into Postman.
/upload-file/
Convert documents (PDF, Word, Excel) and images to plain text.
| Parameter | Type | Required | Description |
|---|---|---|---|
| file | File | Yes | File to be processed (PDF, DOC, DOCX, XLS, XLSX, PNG, JPG) |
| file_type | String | No | Explicitly specify file type (e.g., 'pdf', 'docx'). Overrides file extension. |
Success Response (200 OK):
{
"message": "File processed successfully",
"extracted_text": "The full extracted text content...",
"pages": [
{ "page": 1, "text": "Page 1 text..." } // Only for PDF files
],
"download_link_txt": "/download/yourfile.txt",
"download_link_json": "/download/yourfile.json"
}
Error Response (4xx/5xx):
{
"detail": "Error message describing the issue"
}
// Set your API endpoint
$apiUrl = 'http://your-domain.com/upload-file/';
$filePath = '/path/to/your/document.pdf'; // Can be .pdf, .docx, .xlsx, .png, etc.
// 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 -X POST \
'http://your-domain.com/upload-file/' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@/path/to/your/document.pdf;type=application/pdf'
/download/{filename}
Download previously converted output files using the provided download link (supports .txt and .json).
| Parameter | Type | Required | Description |
|---|---|---|---|
| filename | String | Yes | Name of the file to download (as provided in the upload response) |
// 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";
}
}