# Translate a PDF with an API and keep the layout

> Translate a PDF over HTTP and get back the same-layout translated PDF as base64, with curl, Python or Node. Scanned PDFs work too.

Canonical: https://reducto.ai/cookbooks/translate-pdf-api-keep-layout

POST the PDF to `https://reducto.ai/api/tools/translate-pdf` with the target language. The response carries `output.pdf_base64`: the translated PDF with the same pages, columns, tables and images. Decode it and save it. Files up to 5 pages run with no key; send `Authorization: Bearer $REDUCTO_API_KEY` for the whole file, billed to your Reducto credits.

## How it works

1. Reducto Parse (`r-1`) reads every block on each page with its bounding box, using OCR on scanned pages.
2. Text blocks are translated; figures, tables of numbers, equations and page numbers are left alone.
3. Each translation is drawn back into its original box, in a condensed face first and a smaller size only if needed.

## curl

```bash
curl -s https://reducto.ai/api/tools/translate-pdf \
  -H "Authorization: Bearer $REDUCTO_API_KEY" \
  -F file=@contract.pdf -F target_language=English \
  | jq -r .output.pdf_base64 | base64 --decode > contract.en.pdf
```

## Python

```python

with open("contract.pdf", "rb") as f:
    r = requests.post(
        "https://reducto.ai/api/tools/translate-pdf",
        headers={"Authorization": f"Bearer {os.environ['REDUCTO_API_KEY']}"},
        files={"file": f},
        data={"target_language": "English"},
    )
r.raise_for_status()
out = r.json()["output"]
open("contract.en.pdf", "wb").write(base64.b64decode(out["pdf_base64"]))
print(out["pdf_layout"])  # blocks overlaid, shrunk and overflowed
```

## Node

```ts

const form = new FormData();
form.append("file", new Blob([await readFile("contract.pdf")]), "contract.pdf");
form.append("target_language", "English");
const res = await fetch("https://reducto.ai/api/tools/translate-pdf", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.REDUCTO_API_KEY}` },
  body: form,
});
const { output } = await res.json();
await writeFile("contract.en.pdf", Buffer.from(output.pdf_base64, "base64"));
```

## Without a key

With no key, a file over 5 pages returns the first 5 pages with `partial: true` and a `signup_required` block. Ask your user to create a free Reducto account, then repeat the request with `Authorization: Bearer <key>`. See [agent signup](https://reducto.ai/tools/agent-self-signup).

## Known gaps

Right-to-left targets such as Arabic are not supported for the layout PDF. The original text stays under the white cover, and font size is estimated from each box.

Related: [Translate PDF](/tools/translate-pdf), [Translate a research paper](/tools/translate-research-paper), [all translators](/tools/translate).
