cd /news/ai-tools/how-to-translate-pdfs-programmatical… · home › topics › ai-tools › article
[ARTICLE · art-180301] src=nutrient.io ↗ pub= topic=ai-tools verified=true sentiment=↑ positive

How to translate PDFs programmatically and keep the layout

Nutrient released a PDF translation API that accepts a source PDF and a target language and returns a translated PDF with the same pages and structure, supporting 13 languages with $5 of free usage per month. Nutrient states that PDFs store positioned glyphs rather than paragraphs, so the API runs an extract, translate, rebuild pipeline that performs OCR on scanned pages and reports how many text blocks, if any, remained untranslated. Nutrient notes that LLM translation handles document context well but its output needs a check before it reaches readers.

key takeaway

Nutrient's PDF translation API returns a translated PDF in one call across 13 languages, running OCR on scanned pages and reporting the count of text blocks left untranslated so callers can catch gaps.

by read12 min views2 publishedDec 2, 2026
How to translate PDFs programmatically and keep the layout
Image: Nutrient (auto-discovered)

Table of contents #

Send a PDF and a target language to the Nutrient PDF translation API and get a translated PDF back, page for page, in 13 languages. Start free with $5 of usage every month.

  • A PDF stores positioned glyphs, not paragraphs, so translating one means pulling the text out, translating it, and fitting it back onto the page.
  • Large language model (LLM) translation handles document context well, but its output needs a check before it reaches readers.
  • The Nutrient PDF translation API runs the whole pipeline in one call and returns a PDF with the same pages.
  • Scanned pages are recognized before translation, and the response reports how many text blocks, if any, stayed untranslated.

Translating a 40-page installation manual and getting back a PDF that still looks like the manual takes more than a translation model. The text has to come out of the file, go through that model, and land back on pages that were laid out for the original language.

This post covers where that process breaks and how LLM translation compares with classic machine translation on documents. It also shows how to translate PDFs programmatically with the Nutrient PDF translation API, including scanned pages and long documents.

In this post, PDF translation means turning a source PDF into a translated PDF: same pages, same structure, text in the target language. Copying the text into a translator is a different job, because it returns translated text, not a PDF.

Why translating a PDF is harder than translating its text #

A Word file stores paragraphs, but most PDFs don’t. They describe where each glyph sits on the page, and the sentence, the table cell, and the reading order only exist in the reader’s head. Every PDF translation tool has to deal with the problems below before and after the translation itself.

Problem What goes wrong
Reading order Columns, sidebars, captions, and footnotes are drawn in whatever order the authoring tool chose. Extracted text can splice sentences across columns.
Text length A translation rarely matches the source length. German and French usually run longer than English, and the longer text still has to fit the same box.
Fonts Many PDFs embed only the glyphs the original text used. The translation needs characters the embedded font doesn’t contain.
Scanned pages A scan is an image. With no text layer, there’s nothing to extract until optical character recognition (OCR) reads the words.
Text in pictures Labels in diagrams, screenshots, and charts are pixels, even in a born-digital PDF.
Writing direction Arabic reads right to left, so a faithful page often needs mirrored columns and tables, not only reversed lines.

A better translation model fixes none of these. Each one affects whether the output still looks like the original or comes back as a wall of text in the new language.

The extract, translate, rebuild pipeline #

Teams that build PDF translation themselves usually end up with the same three stages.

  1. Extraction parses the PDF into text blocks with positions and reading order after OCR has run on any scanned pages.
  2. Translation sends the blocks to a machine translation API or an LLM with enough context to keep terms consistent.
  3. Rebuilding writes the translated text back into each block’s position, shrinks or reflows it to fit, substitutes fonts that cover the target script, and mirrors the page for right-to-left languages.

Translation is the smaller part of the job. Extraction needs a parser that recovers reading order, which a plain text dump can’t do. Rebuilding means editing content streams, fonts, and layout without breaking the file. Every new document type adds edge cases to both stages, and a scanned contract breaks in different places than a three-column brochure.

Machine translation vs. LLM translation for documents #

Machine translation APIs run neural models trained for translation, one segment at a time. That keeps them fast, and their output is predictable. Unless the application sends the surrounding text along, the model never sees the rest of the document, so the same term can come out one way on page 2 and another on page 30.

LLM translation sends larger pieces of the document to a general language model. With that context, the model can keep terminology consistent across sections and follow instructions about tone. It handles mixed content as well, such as a sentence with a part number in the middle. On the other hand, a language model can drop a phrase, add one, or answer in the wrong language, so its output needs validation more often than a dedicated translation engine’s does.

For PDFs, neither choice removes the extraction and rebuild work. The model sets the quality of the sentences, but whether the result is still a usable PDF depends on the document pipeline. Data extraction has the same division of labor, and the post on using an LLM directly vs. a document parsing API goes into it in more depth.

Translate a PDF with one API call #

The Nutrient PDF translation API runs extraction, translation, and rebuilding as one request. It translates the text with an AI model, checks each translated block, and returns a PDF with the same number of pages as the original. Pages with a text layer keep their layout, and scanned pages are recognized before they’re translated.

The PDF translation API is experimental. It’s available to every organization, and Nutrient is still improving it, so its request options, output, and price can change. The PDF translation guide documents the current options.

Prerequisites

The examples need the following:

  • A Nutrient API key from the Nutrient dashboard(opens in a new tab) . A test key returns a placeholder PDF without translating it, so use a live key to see real output.
  • curl , or Python 3 with therequests package (pip install requests ).
  • A PDF with up to 50 pages. The examples use a file named manual.pdf .

Step 1: Send a PDF and a target language

The request sends the PDF in the file part and the options as JSON in the data part. The response body is the translated PDF. This example translates manual.pdf into German:

A translation can take several minutes, and a synchronous request fails with status 504 if it doesn’t finish within 10 minutes. That’s why the Python example sets an 11-minute timeout. The curl example waits as long as it needs to.

The targetLanguage value is an ISO 639-1 code. The API translates into Arabic (ar), Chinese (Simplified, zh), Dutch ( nl), English ( en), French ( fr), German ( de), Greek ( el), Italian ( it), Japanese ( ja), Polish ( pl), Portuguese ( pt), Russian ( ru), and Spanish ( es). It detects the source language itself, so the request only names the target. The request takes three options:

Option Default What it does
targetLanguage Required The language to translate into, as an ISO 639-1 code.
translateTextInImages true Translates the text inside pictures on pages with a text layer.
mirrorLayout true Applies only when the target is Arabic. Mirrors pages with a text layer so they read right to left.

The API rejects an unknown option with status 400, so a typo in an option name fails fast instead of being ignored.

Step 2: Check for untranslated blocks

A translated document can come back with a few blocks in the source language. When the translation of a text block fails validation, that block keeps its original text, and the request still succeeds. The X-Nutrient-Untranslated-Blocks response header gives the number of blocks left over, and it’s absent when everything was translated.

The curl example saved the response headers to headers.txt, so one command shows the count:

In Python, read the header from the response of the previous step:

A nonzero count doesn’t mean the request failed. The PDF is usable, and a reviewer can decide whether the leftover blocks matter.

Step 3: Translate long documents asynchronously

A synchronous request holds the HTTP connection open until the PDF is ready. For long documents, or for a queue of many documents, start an asynchronous run instead. The request is the same, plus a Prefer: respond-async header. The API returns status 202 with a run description, and the application polls the run until it’s done or error:

The Idempotency-Key header is optional but worth sending. If the network drops after the request leaves, sending the same request with the same key returns the original run instead of starting, and paying for, a second translation. Reusing a key with a different PDF or different options returns status 409.

A finished run keeps its status and result for 24 hours, and only the organization that started it can read them. Test API keys can’t start asynchronous runs, so this step needs a live key.

Scanned PDFs, text in pictures, and right-to-left output #

These three cases break a lot of homegrown pipelines. The API handles all of them inside the same request.

Translate scanned PDFs

The API recognizes the text on scanned pages before translating it, so an image-only PDF goes through the same call as a born-digital one, with no OCR step to run first. To make a scan searchable in its original language without translating it, use the PDF OCR API.

Translate text inside pictures

On pages with a text layer, the API also translates text inside pictures, such as the callouts in a diagram. Setting translateTextInImages to false leaves pictures untouched, which suits screenshots of software interfaces that should keep their original labels.

Translate into right-to-left languages

When the target language is Arabic, pages with a text layer are mirrored so they read right to left. Setting mirrorLayout to false keeps the original direction. Arabic is the only right-to-left language among the 13 targets.

Check translations before they reach readers #

The untranslated-block count tells an application what didn’t come back translated. It doesn’t measure whether the translation is correct. Accuracy needs its own checks, and how strict they are depends on what the document is for.

Because the translated PDF has the same pages as the source, a reviewer can compare page 12 with page 12 instead of hunting for where a passage moved. Numbers, units, dates, and proper names are worth a targeted look, because a wrong digit in a dosage table or a torque value matters more than an awkward sentence.

For contracts, regulatory submissions, and anything legally binding, machine translation produces a working copy, not a certified translation. A reviewer who speaks both languages should approve the final version.

Where automated PDF translation fits #

Programmatic translation pays off when the same kind of document arrives often, or when one document has to exist in several languages. Common cases include:

  • Manufacturers translating instructions for use, service manuals, and safety sheets for new markets.
  • Document management and e-learning platforms adding a translate action next to view and download.
  • Claims and intake teams that receive records in another language and need a reading copy for review.
  • Procurement and legal teams that need a working translation of a supplier contract before a certified one is ordered.

Without an API, each of these is a manual roundtrip through a translation tool and a desktop publishing app.

Limits and pricing #

The API accepts documents of up to 50 pages, and a longer document returns status 400. Translation costs $0.10 per page of the translated PDF, and the price includes the AI model, so there’s no separate charge for model usage. Translations that fail or time out aren’t charged. A request with leftover untranslated blocks counts as a completed translation and is charged. While the API is experimental, the page limit and the price can change.

The API pricing page lists plans and rates, and the PDF translation guide covers every option, response, and error code.

FAQ #

Use a tool that rebuilds the document instead of translating extracted text. The Nutrient PDF translation API returns a PDF with the same pages as the original, and pages with a text layer keep their layout. Copying text into a translator keeps the words but loses the layout. Yes. The Nutrient PDF translation API recognizes the text on scanned pages before translating it, so scans and born-digital PDFs go through the same request.

It translates into Arabic, Chinese (Simplified), Dutch, English, French, German, Greek, Italian, Japanese, Polish, Portuguese, Russian, and Spanish. The target is set with an ISO 639-1 code, such as de for German, and the source language is detected automatically.

Machine translation APIs use models trained only for translation and work segment by segment. LLM translation uses a general language model that can keep terminology and tone consistent across a whole document, but its output needs validation, because a language model can drop or add content.

The Nutrient PDF translation API costs $0.10 per page of the translated PDF, including the AI model. Failed and timed-out translations aren’t charged.

Send the PDF and a JSON data part with targetLanguage to https://api.nutrient.io/processor/translate with the requests package, and write the response body to a file. Step 1 of this article has the complete example.

Next steps #

Get an API key from the Nutrient dashboard(opens in a new tab) and run the Step 1 example on a real production document rather than a sample. Compare the pages side by side and check the untranslated-block count. Those two checks show what review each document type needs before its translations reach readers.

── more in #ai-tools 4 stories · sorted by recency
── more on @nutrient 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/how-to-translate-pdf…] indexed:0 read:12min 2026-12-02 · —