---
title: "Extract text from PDF"
method: POST
path: "/pdf/to-text"
tags: ["PDF"]
---

# Extract text from PDF

`POST /pdf/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/pdf/to-text`
- Auth: API key in header `X-API-Key`

Extract text content from a PDF document.

For native PDFs (created digitally), text is extracted directly.
For scanned PDFs, OCR is used automatically when `ocr_fallback` is enabled.

## Options
- **ocr_language**: Language code for OCR (default: "eng")
- **ocr_fallback**: Whether to use OCR if no text found (default: true)

## 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)
