Document Text Extraction API Documentation
Welcome to the Document Text Extraction API documentation. This API allows you to extract text from various document formats, including PDF, DOCX, RTF, TXT files, and images requiring OCR processing.
Getting Started
To use the Document Text Extraction API, you need to send HTTP requests to our endpoints. The API accepts various document formats via POST requests and returns structured JSON responses with the extracted text and relevant metadata.
Supported File Types
- PDF - Portable Document Format files
- DOCX - Microsoft Word documents
- RTF - Rich Text Format files
- TXT - Plain text files
- Images - JPG, JPEG, PNG, TIFF, BMP (processed with OCR)
Base URL
https://anyparser.replit.app/api/v1
Try it Out
You can test the API right away using our interactive demo page. The demo provides a user-friendly interface where you can upload your PDF files and see the extraction results in real-time.
Authentication
Authentication is currently not required for this demo API. In a production environment, you would typically include an API key in your requests.
API Endpoints
Extract text from various document formats. Supports PDF, DOCX, RTF, TXT files, and images with OCR.
Request
Send a multipart/form-data request with the document file:
| Parameter | Type | Required | Description |
|---|---|---|---|
| file | File | Yes | The document file to process: PDF, DOCX, RTF, TXT, or image files (max 16MB) |
Response
Returns a JSON object with the extracted text and metadata:
{
"status": "success",
"filename": "document.pdf",
"file_size": 42500,
"pages": 2,
"metadata": {
"Author": "John Doe",
"Creator": "Microsoft Word",
"Producer": "Adobe PDF Library 15.0",
"CreationDate": "2023-01-15T08:30:00Z"
},
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
"cleaned_text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
"ocr_applied": false,
"validation": {
"is_valid": true,
"quality_metrics": {
"overall_quality_score": 0.92,
"word_count": 450,
"character_count": 2800,
"words_per_page": 225
},
"warnings": [],
"language_detection": "en",
"potential_pii": false
},
"processing_info": {
"timestamp": "2025-04-04T14:35:21.451Z",
"api_version": "v1"
}
}
{
"status": "error",
"message": "No file part in the request",
"code": "MISSING_FILE"
}
{
"status": "error",
"message": "Error processing PDF: Internal server error",
"code": "PROCESSING_ERROR"
}
Check if the API is up and running.
Request
No parameters required.
Response
{
"status": "success",
"message": "API is running",
"version": "v1"
}
Request/Response Format
Response Fields
| Field | Type | Description |
|---|---|---|
| status | String | "success" or "error" |
| filename | String | The name of the uploaded file |
| file_size | Number | Size of the file in bytes |
| pages | Number | Number of pages in the PDF |
| metadata | Object | PDF metadata such as author, creation date, etc. |
| text | Array | Array of objects containing page number and extracted text |
| ocr_applied | Boolean | Whether OCR was used for text extraction |
| validation | Object | Text validation results and quality metrics |
| processing_info | Object | Information about the processing request |
Error Handling
The API returns appropriate HTTP status codes along with JSON error responses that include a status, message, and error code.
| Status Code | Error Code | Description |
|---|---|---|
| 400 | MISSING_FILE | No file was uploaded in the request |
| 400 | EMPTY_FILENAME | File was uploaded but has no filename |
| 400 | INVALID_FILE_TYPE | Uploaded file is not a PDF |
| 413 | FILE_TOO_LARGE | Uploaded file exceeds the size limit (16MB) |
| 500 | PROCESSING_ERROR | Error occurred while processing the PDF |
| 500 | FILE_SAVE_ERROR | Error saving the uploaded file |
| 500 | SERVER_ERROR | Internal server error |
Code Examples
# Extract from PDF
curl -X POST \
-F "file=@document.pdf" \
https://anyparser.replit.app/api/v1/extract
# Extract from DOCX
curl -X POST \
-F "file=@document.docx" \
https://anyparser.replit.app/api/v1/extract
# Extract from image with OCR
curl -X POST \
-F "file=@scanned_document.jpg" \
https://anyparser.replit.app/api/v1/extract
import requests
url = 'https://anyparser.replit.app/api/v1/extract'
files = {'file': open('document.pdf', 'rb')}
response = requests.post(url, files=files)
data = response.json()
if response.status_code == 200:
# Process successful response
print(f"Extracted text, {len(data['text'])} characters")
print(f"Text content preview: {data['text'][:100]}...")
// Using fetch API
const url = 'https://anyparser.replit.app/api/v1/extract';
const fileInput = document.getElementById('fileInput'); // Assuming you have a file input element
const formData = new FormData();
formData.append('file', fileInput.files[0]);
fetch(url, {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
// Process successful response
console.log(`Extracted ${data.text.length} pages of text`);
data.text.forEach(page => {
if (data.status === 'success') {
// Process successful response
console.log(`Extracted text, ${data.text.length} characters`);
console.log(`Text content preview: ${data.text.substring(0, 100)}...`);
}
.catch(error => {
console.error('Network error:', error);
});
<?php
$url = 'https://anyparser.replit.app/api/v1/extract';
$file = new CURLFile('document.pdf', 'application/pdf', 'document.pdf');
$data = array('file' => $file);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
if (isset($result['status']) && $result['status'] === 'success') {
// Process successful response
echo "Extracted " . count($result['text']) . " pages of text\n";
foreach ($result['text'] as $page) {
echo "Page " . $page['page'] . ": " . substr($page['content'], 0, 100) . "...\n";
}
if (isset($result['status']) && $result['status'] === 'success') {
// Process successful response
echo "Extracted text, " . strlen($result['text']) . " characters
";
echo "Text content preview: " . substr($result['text'], 0, 100) . "...
";
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;
public class PDFExtractExample {
public static void main(String[] args) {
String url = "https://anyparser.replit.app/api/v1/extract";
File pdfFile = new File("document.pdf");
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost uploadFile = new HttpPost(url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody(
"file",
pdfFile,
ContentType.APPLICATION_OCTET_STREAM,
pdfFile.getName()
);
HttpEntity multipart = builder.build();
uploadFile.setEntity(multipart);
try (CloseableHttpResponse response = httpClient.execute(uploadFile)) {
HttpEntity responseEntity = response.getEntity();
String responseString = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8);
JSONObject result = new JSONObject(responseString);
if (result.getString("status").equals("success")) {
// Process successful response
String extractedText = result.getString("text");
System.out.println("Extracted text, " + extractedText.length() + " characters");
System.out.println("Text content preview: " +
(extractedText.length() > 100 ? extractedText.substring(0, 100) + "..." : extractedText));
} else {
// Handle error
System.out.println("Error: " + result.getString("message"));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Limitations
- Maximum file size: 16MB
- Supported formats: PDF, DOCX, RTF, TXT, JPG, JPEG, PNG, TIFF, BMP
- OCR processing may be less accurate for low-quality scans, handwritten text, or documents with complex layouts
- Currently supports English language text best; other languages may have reduced accuracy
- DOCX files: Only extracts text content, formatting and embedded objects are not preserved
- RTF files: Formatting codes are stripped, only plain text is extracted
- Rate limiting: 10 requests per minute for demo purposes
Frequently Asked Questions
What types of documents can be processed?
The API can process multiple document formats:
- PDF files: Both text-based PDFs and scanned documents requiring OCR
- DOCX files: Microsoft Word documents with text and table content
- RTF files: Rich Text Format documents
- TXT files: Plain text files with automatic encoding detection
- Image files: JPG, PNG, TIFF, BMP files processed with OCR
How accurate is the OCR?
OCR accuracy depends on the quality of the scanned document. Clean, high-resolution scans typically achieve 90%+ accuracy. Low-resolution or poor-quality scans may have lower accuracy. The API includes quality metrics to help you evaluate the extraction results.
Is the API suitable for processing sensitive documents?
The API includes basic detection for potential personally identifiable information (PII). However, for highly sensitive documents, we recommend using a self-hosted version of the service rather than a cloud API.
What languages are supported?
The API currently works best with English text but can also handle many other Latin-based scripts with reasonable accuracy. Support for additional languages and scripts is planned for future releases.