Extracting PDF with OCR
Description
PDFs extraction system that processes documents with a 3 step workflow designed for efficient file management up to 50 MB. It uses fragmented loads (1 MB per chunk) with Base64 encoding and returns JSON structured data extracted by OCR and AI.
Specializes in: complex documents such as constitutional acts, notary documents and CFE receipts.
Specifications
| Specification | Value |
|---|---|
| Maximum file size | 50 MB |
| Input format | PDF encoded at Base64 |
| Output format | JSON structured |
| Expiry of sitting | 1 hour |
Processing Flow
INIT → UPLOAD-CHUNK (×N) → COMPLETE → Resultado JSON
Endpoints
1. INIT - Session initiation
POST /v4/document/extract/pdf/init
Headers:
Request-Id(UUID v4, required)Language(in / es, optional)Authorization(Bearer token)
Body: empty
Answer:
upload_id- Unique session identifierfile_size- Expected total Byteschunk_size- Individual chunk size (typically 1 MB)total_chunks- Number of necessary chunksexpires_at- Expirand time
2. UPLOAD-CHUNK - Loading of Fragments
POST /v4/document/extract/pdf/upload-chunk
Important: The chunks use zero base indexation (0, 1, 2... N-1).
Body:
upload_id- INIT's responsechunk_number- Retirement (base -0)chunk_data- PDF segment encoded at Base64
Answer:
progress_percent- Percentage of completenessuploaded_chunks- count of chunks receivedremaining_chunks- Still necessaryis_complete- Flag boolan when all chunks are received
3. COMPLETE - Completion of processing
POST /v4/document/extract/pdf/complete
Body:
upload_id- Session identifiername- Optional user identifier
Answer (example Constitutional Act):
{
"eventId": "UUID",
"status": "SUCCESS",
"content": {
"data": {
"capital_shareholders": {},
"company_data": {},
"initial_governing_bodies": {},
"main_corporate_purpose": []
},
"extra": {
"document_type": "ACTA_CONSTITUTIVA",
"country_code": "MX",
"page_count": 22
}
},
"processingTime": 1234
}
Types of Supported Documents
- Constitutional acts
- Notary
- CFE copies
- Commercial contracts
- Financial statements
- Legal agreements
Note: For identification documents (INE), JAAK provides specialized endpoints.
Critical Points of Implementation
Indexation Ground Zero
First chunk's always 0No. 1. To 19 total chunks, send 0-18.
Auto- Server Setup
Never compute manually chunk_size or total_chunks - INIT response provides these values.
Expiration of Session
Each session expires 1 hour after creation.
Flexibility in Loading Chunks
Send chunks in any order but they have to get here before calling COMPLETE.
JavaScript implementation
class JAKPDFExtractor {
async extractPDF(file) {
// 1. Validar archivo
// 2. Convertir a Base64
// 3. INIT: get chunk parameters
const initRes = await this._initUpload();
// 4. UPLOAD-CHUNK: send fragments
for (let i = 0; i < initRes.total_chunks; i++) {
await this._uploadChunk(i, chunks[i]);
}
// 5. COMPLETE: finalizar procesamiento
return await this._completeUpload();
}
}
Timeouts Recommended
| Operation | Timeout |
|---|---|
| INIT | 10 seconds |
| UPLOAD-CHUNK | 30 seconds per chunk |
| COMPLETE | 120 seconds (processing) OCR) |
Errors Management
| Code | Description |
|---|---|
| 400 | Invalid file size / format or incomplete chunks |
| 401 | Unauthorized / expired Token |
| 404 | Expiry or non-existent meeting |
| 429 | Rate limitation (100 req / min by API ) |
| 500 | Failed processing OCR |
Example error:
{
"errorCode": "INCOMPLETE_UPLOAD",
"message": "Missing chunks: 3, 7, 12",
"statusCode": 400
}
Best Practices
- Revalidation: Check PDF type, size (max 50MB) and extension before loading
- Session management: Storage
upload_idfor incremental loads - Retry logic: Exponential backoff (1s, 2s, 4s) for failed chunks
- Monitoring of progress: Show percentage and count of chunks to users
- Security: Never explain API front keys; use proxy backend
- HTTPS only: All communications should use TLS 1.3
Security and Privacy
- No persisting document storage and memory processing
- Automatic login after 1 hour
- Full-track audit track
Request-IdandeventId - Compliance with Mexican data protection regulations