---
title: "Extract text from any document"
method: POST
path: "/any/to-text"
tags: ["Smart Conversion"]
---

# Extract text from any document

`POST /any/to-text`

## Request

- Base URL: `https://api.filegraph.ai` (the document declares no server; this is the origin it was published from)
- URL: `https://api.filegraph.ai/any/to-text`
- Auth: API key in header `X-API-Key`

Smart text extraction that automatically detects the input format and uses
the appropriate extraction method.

## Supported Formats
- **PDF**: Native text extraction, falls back to OCR for scanned PDFs
- **DOCX**: Microsoft Word documents
- **XLSX**: Microsoft Excel (extracts cell contents)
- **PPTX**: Microsoft PowerPoint (extracts slide text)
- **Images**: PNG, JPEG, TIFF, BMP (uses OCR)
- **HTML**: Extracts visible text content

## How It Works
1. Detects file format from content (not just extension)
2. Routes to appropriate extraction module
3. For PDFs: tries native extraction first, falls back to OCR if no text found
4. Returns extracted text with metadata about source format

## Example Usage

```python
import httpx

with open("document.pdf", "rb") as f:
    response = httpx.post(
        "https://api.filegraph.ai/any/to-text",
        headers={"X-API-Key": "your-api-key"},
        files={"file": f},
    )
print(response.json()["text"])
```

## Query parameters

- `ocr_language` string
- `ocr_fallback` boolean

## Response `200`

Text successfully extracted

- TextExtractionResponse: Response for text extraction endpoints.
  - `text` string, required: Extracted text content
  - `format_detected` string, required: Detected input format (e.g., 'pdf', 'docx', 'image')
  - `word_count` integer, required: Number of words extracted
  - `char_count` integer, required: Number of characters extracted
  - `used_ocr` boolean, required: Whether OCR was used for extraction
  - `metadata` object: Additional format-specific metadata

## Other responses

- `400`: File format not supported
- `401`: Invalid or missing API key
- `402`: Insufficient credits for this operation
- `413`: File exceeds size limit
- `422`: File processing failed
- `500`: Unexpected internal error

---

[API](https://skmtc.dev/filegraph/apis/docconvert-api.md) · [All operations](https://skmtc.dev/filegraph/apis/docconvert-api/llms.txt) · [OpenAPI document](https://skmtc.dev/filegraph/apis/docconvert-api/revisions/436255c85bd4?raw)
