---
title: "Extract text from a PDF, or search within a PDF"
method: POST
path: "/api2/pdftotext"
tags: ["PDF To Text"]
---

# Extract text from a PDF, or search within a PDF

`POST /api2/pdftotext`

Two operations selected by `action`:
  - `Convert` (default) — extract text, returned as `text/plain` (or `text/html` if
    `output_format=Html`) in the response body.
  - `Search` — find a substring; response is JSON array of `{ page, x, y, width, height }`
    text-position objects.

Input is either a multipart upload (form field `file`) or a `url` referencing a PDF.

## Request body

- PdfToTextParameters
  - `key` string, uuid, required
  - `async` boolean
  - `action` 'Convert' | 'Search' — `Convert` extracts text; `Search` returns matching `{page,x,y,w,h}` boxes for `search_text`.
  - `url` string — URL to the PDF input. Alternative to a multipart upload.
  - `start_page` integer — First page to process (1-based).
  - `end_page` integer — Last page to process. 0 = last page of the document.
  - `user_password` string — Password for opening encrypted input PDFs.
  - `text_layout` 'Original' | 'Reading' — `Original` preserves the PDF's spatial layout; `Reading` reorders into reading sequence.
  - `output_format` 'Text' | 'Html'
  - `timeout` integer
  - `search_text` string — Substring to find when `action=Search`.
  - `case_sensitive` boolean
  - `whole_words_only` boolean
  - `raw_parameters` string

## Response `200`

Plain text (or HTML, or JSON array for Search) in body.

## Other responses

- `202` — Async accepted. Poll `/api2/asyncjob`.
- `400` — Missing PDF input (no `url` and no upload), or invalid `action`.
- `401` — Unauthorized.
- `429` — Concurrency throttled.
- `499` — Extraction failed — corrupt PDF, wrong password, etc.

---

[API](https://skmtc.dev/selectpdf/apis/selectpdf-rest-api.md) · [All operations](https://skmtc.dev/selectpdf/apis/selectpdf-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/selectpdf/selectpdf-rest-api/revisions/3e8de86ac045/schema)
