Replace text in an existing PDF, by API

Most PDF tools regenerate a page or paste new text over the old. This one rewrites the matched words in place: the replacement is set in the font the document embeds, the line keeps its position, and the page is rendered before and after to prove nothing else moved. If something would move, the edit is rolled back and the response says why.

How it works

1

Find

The text to change, matched exactly, case-insensitively, by whole word or by regex; scoped to pages, a region, an anchor or the nth occurrence.

2

Rewrite

The new text is written in the document's own font (or a metric twin with the same widths when the font is not embedded). Longer text is fitted on the line or the paragraph re-flows.

3

Verify

The changed region is rendered before and after and compared outside the edit. Zero collateral pixels is the norm; anything else rolls the change back.

The request

{"source": {"url": "https://example.com/agreement.pdf"},
 "edits": [{"find": "$4,200", "replace": "$4,800"}]}

Or as one curl with a local file, getting the PDF straight back:

curl -sS https://api.niubai.vip/v1/edit -F file=@agreement.pdf \
  -F 'edits=[{"find": "$4,200", "replace": "$4,800"}]' -H "Accept: application/pdf" -o agreement.edited.pdf

Real output

beforeBefore: A fee in an agreement changed from $4,200 to $4,800; the embedded font and the rest of the line stay as the generator wrote them.
afterAfter: A fee in an agreement changed from $4,200 to $4,800; the embedded font and the rest of the line stay as the generator wrote them.
A fee in an agreement changed from $4,200 to $4,800; the embedded font and the rest of the line stay as the generator wrote them. Produced by the API itself; more: example 03 · example 07 · example 10, and all ten on the examples page.

From an AI agent

Install once (claude mcp add pdfedit -- npx -y @niubai/pdfedit-mcp, or the buttons on the Cursor and VS Code pages; no Node: npx skills add zp130221/pdfedit-mcp), then say it in plain words:

In ./agreement.pdf change the monthly fee from $4,200 to $4,800.

Questions

Does the replacement use the same font?

Yes when the document embeds enough of it (any page's subset counts). Otherwise a metric-compatible twin with the same character widths stands in: Arial, Times New Roman, Courier New, Calibri, Cambria, Georgia, Segoe UI, Palatino, Book Antiqua, Bookman, Century Gothic and New Century Schoolbook all have one. The response reports font_source and font_used for every change.

What if the new text is longer?

By default it is fitted on the line with a slight compression, or the paragraph re-flows when you ask for fit: reflow. fit: strict refuses instead of squeezing.

Can it change the same phrase on every page?

Yes. An edit matches every occurrence unless you scope it: pages, first or last occurrence, a region, an anchor phrase, or the exact span ids returned by the text endpoint.

Does it work on scanned PDFs?

Scanned pages have no text layer; with OCR on, the text is found by OCR and the replacement is drawn as pixels, verified by re-rendering. Those pages count as five.

What does it cost?

Per page touched by an applied edit. 200 pages a month free with a key, 20 a day per IP with none (outputs marked SAMPLE); paid plans from $9 a month.

Also: PDF redaction API that removes the text for real · Fill PDF forms by API. Full reference: API reference · GitHub.