Endpoint reference

POST /api/detect-fields

Suggest fillable fields for a flat PDF. It finds the blanks that are drawn on the page as lines, boxes, underscores and checkboxes, and returns them as text and checkbox fields you can review and send to /api/add-fields.

A flat PDF has no form fields: the blanks are just drawing. This endpoint reads the page's vector drawing and text layer, and works out where a person would write. Each result has a name taken from the nearest printed label, a position, a size and a confidence from 0 to 1. It uses fixed geometry rules, not a model, so the same file always gives the same answer. It detects fields that are drawn. A blank that is only empty space, a scanned page (a picture, with no drawing or text to read), or a shaded area with no outline has nothing to detect. Treat the result as a list of suggestions to review, not a finished form.

Request

Method: POST. URL: https://pdfops.dev/api/detect-fields. Body: multipart/form-data.

FieldTypeRequiredDescription
pdfFile (PDF binary)YesExactly one PDF, up to 4 MB and 2,000 pages. The whole request must stay under 4.5 MB, Vercel's platform request limit.
pagesStringNoPages to analyse, 1-based: 1-3,5,8-. Default: every page, up to max_pages.
max_pagesIntegerNo1 to 100, default 40. At most this many of the selected pages are analysed; the rest are reported through nextPage and nextPages (continue as described under truncated).
min_confidenceNumberNo0 to 1, default 0.4. Fields below it are dropped. The default drops only the weakest candidates (unlabelled shapes score about 0.3 to 0.4); 0.6 gives slightly higher precision and about a quarter fewer checkboxes (see What it finds).
passwordStringNoOpens a PDF that needs a user password. Not needed for owner-locked files with an empty user password.
formatStringNojson (default) returns the suggestions. pdf detects and adds the fields in the same request and returns the fillable PDF; see Detect and add in one call.

The optional X-API-Key header works as on /api/merge: no header is anonymous, 100 requests per IP per month; a valid key uses your tier's quota; an invalid or revoked key returns 401 invalid_api_key. A successful (2xx) call counts 1 request. Check consumption with GET /api/usage.

Response

On success: 200 OK, Content-Type: application/json. This is a real answer for a one-page membership form, trimmed to two of its eight fields:

{
  "pages": [
    {
      "page": 1,
      "width": 612,
      "height": 792,
      "fields": 8
    }
  ],
  "count": 8,
  "truncated": false,
  "fields": [
    {
      "type": "text",
      "name": "Full name",
      "page": 1,
      "x": 115,
      "y": 688,
      "width": 285,
      "height": 14,
      "label": "Full name",
      "confidence": 0.85
    },
    {
      "type": "text",
      "name": "Date of birth",
      "page": 1,
      "x": 130,
      "y": 658,
      "width": 130,
      "height": 14,
      "label": "Date of birth",
      "confidence": 0.85
    },
    ...
  ]
}
KeyDescription
countNumber of fields returned.
pages[]One entry per page returned: page, width and height in points as displayed, and fields, how many of the returned fields are on it.
fields[].typetext for a rule, a box or a run of underscores; checkbox for a small square or circle.
fields[].nameFrom the nearest printed label (for a text field: inside the box, to its left, above it or below it; for a checkbox: to its left or right), or field p1 3 style when there is none. Unique in the response, about 60 characters at most, no dot, and not the name of a field already in the PDF.
fields[].page, x, y, width, heightThe rectangle, in the frame described under Coordinates.
fields[].labelThe printed label the name came from, empty when none was found. Not an /api/add-fields key; it is ignored there.
fields[].confidence0 to 1. Higher when a label is attached and the shape is clear. Not an /api/add-fields key; it is ignored there.
truncatedtrue when the answer is incomplete: more selected pages than max_pages, more than 200 fields (the most /api/add-fields takes), or the call stopped at its time or work limit before it read every page. Pages are returned whole, except that a first page that alone has more than 200 fields returns its 200 most confident ones. Continuation, the one rule: add the returned fields to the PDF (JSON mode: POST them to /api/add-fields; format=pdf already did), then send the resulting PDF again with pages set to nextPages (X-PDFops-Next-Pages); repeat until truncated is false. Each round finds new fields only because the PDF now holds the earlier ones. Sending the original PDF again repeats the same names and is not supported.
nextPage, nextPagesOnly when truncated: nextPage is the first page not done, and nextPages is exactly the pages not done as a page spec such as 5,9 or 4-7: pages beyond max_pages, pages the call stopped before, and a page that alone was cut at 200 fields (it stays in until it yields nothing new). A sparse selection stays sparse (nextPage followed by a dash would not). Send the PDF with the fields added back with pages set to nextPages.
pagesSkippedOnly when present: pages that were not analysed. { "page": 3, "reason": "too_complex" }: the page holds more drawn shapes or text than the per-page limits (more than 3,000 rectangles, 8,000 rules of one direction or 6,000 text segments; the largest page of our 38-form test set had 637 rectangles and 1,414 rules); sending it again gives the same answer, so it is not in nextPages. { "page": 4, "reason": "deadline" }: the call stopped at its time or work limit (about 8 seconds of work) before reaching the page; it is in nextPages and nothing was lost.
notePresent whenever there is something to say besides the fields: nothing was found (count 0), pages were skipped, or the answer is truncated, in which case it states how to continue.
noteOnly when count is 0: a short sentence saying that nothing drawn was found.

No fields found is a 200 with count: 0 and a note, not an error. On any failure: 4xx or 500, Content-Type: application/json, body is { "error": "<code>", "details": "..." }.

Coordinates

Each field is already in the frame /api/add-fields reads, which is also the frame of /api/edit and /api/find-text: PDF points, 72 to the inch, measured from the bottom-left corner of the page as a viewer shows it (after any page rotation and crop). x and y are the field's bottom-left corner. Every rectangle lies inside the page and each side is at least 4 points, so each entry is a valid element of the fields array of /api/add-fields as it is.

Detect and add in one call

Send format=pdf and the endpoint detects the fields, adds them with the same code as /api/add-fields, and returns the fillable PDF. It is one request and counts as one. pages, max_pages, min_confidence and password work as above. Nothing is reviewed in between, so use it when you will check the result afterwards, or when any suggested field is better than none. For a review step first, use the recipe below.

The examples on this page use the one-page sample form at pdfops.dev/sample-flat-form.pdf; download it first with curl -sO https://pdfops.dev/sample-flat-form.pdf.

curl -sO https://pdfops.dev/sample-flat-form.pdf
curl -s -D headers.txt -X POST https://pdfops.dev/api/detect-fields \
  -H "X-API-Key: $PDFOPS_API_KEY" \
  -F "pdf=@sample-flat-form.pdf" -F format=pdf -o fillable.pdf
cat headers.txt | grep -i '^x-pdfops'
x-pdfops-field-names: ["Full name","Date of birth","Address","Phone","Individual","Family","Signature","Date"]
x-pdfops-fields: 8

Then fill a field by name with /api/fill-form:

curl -s -X POST https://pdfops.dev/api/fill-form \
  -F "pdf=@fillable.pdf" -F 'fields={"Full name":"Ada Lovelace","Individual":"true"}' -o filled.pdf

On success: 200 OK, Content-Type: application/pdf, with these headers:

HeaderDescription
X-PDFops-FieldsHow many fields were added.
X-PDFops-Field-NamesTheir names as a JSON array, in page then top-to-bottom order. Cut at 4 KB: a final "..." entry means more names were added than are listed.
X-PDFops-Truncatedtrue only when something was left out. Nothing is dropped silently.
X-PDFops-Truncated-ByWith it: pages (more selected pages than max_pages), fields (more than 200 fields: whole pages after the cap are left out, and a page that alone has more than 200 keeps its 200 most confident fields), deadline (the call stopped at its time or work limit before reading every page), or several, comma separated.
X-PDFops-Next-PagesWith it: the pages not done, as a page spec (a page cut at 200 fields stays in). The returned PDF already holds the fields found; send it back with pages set to this value and repeat until X-PDFops-Truncated is absent. Names already in the PDF are never suggested again, and a field that is already there is not found a second time. The returned PDF is the input plus the new fields, so it must still fit the 4 MB upload limit to be sent back; a file near that limit cannot be continued. It answers no_fields (with truncated and nextPages in the body) when a round finds nothing new but pages are left.
X-PDFops-Pages-SkippedOnly when present: pages not analysed because they hold more drawn shapes or text than the per-page limits (too_complex). Pages stopped by the time limit are in X-PDFops-Next-Pages instead.

No fields found is an error here: 400 with { "error": "no_fields", "details": "..." } (the body also has truncated, nextPage and nextPages, and pagesSkipped when it applies). You never get back an unchanged PDF that looks like a result. A failed request does not count against your quota. The same errors as the JSON mode apply, plus the errors of /api/add-fields that can still occur (for example a form that is already near the 2,000-field limit).

curl -s -X POST https://pdfops.dev/api/detect-fields -F "pdf=@blank-page.pdf" -F format=pdf
{"error":"no_fields","details":"No fields were found. This looks for blanks that are drawn as lines, boxes, underscores or checkboxes; a form whose blanks are bare space or a scanned image has none to find. No PDF was produced.","truncated":false,"nextPage":null,"nextPages":null}

Recipe: detect, review, add, fill

Detect the fields, look the list over, add the ones you keep, then fill the result. Dropping or renaming entries is a one-line edit with jq:

# 1. detect (keyless calls work; add -H "X-API-Key: ..." for your quota)
curl -s -X POST https://pdfops.dev/api/detect-fields -F "pdf=@sample-flat-form.pdf" -o detected.json
jq -r '.fields[] | [.page, .type, .name, .confidence] | @tsv' detected.json   # review

# 2. add the fields (drop the ones you do not want first, for example by confidence)
jq -c '[.fields[] | select(.confidence >= 0.6)]' detected.json > keep.json
curl -s -X POST https://pdfops.dev/api/add-fields \
  -F "pdf=@sample-flat-form.pdf" -F "fields=<keep.json" -o fillable.pdf

# 3. fill them
curl -s -X POST https://pdfops.dev/api/fill-form \
  -F "pdf=@fillable.pdf" -F 'fields={"Full name":"Ada Lovelace","Individual":"true"}' -o filled.pdf

What it finds

It finds blanks that are drawn as lines, boxes, underscores and checkboxes. It does not find a field that has nothing drawn. Some detections are table cells or rules that are not blanks, and names are often near but not equal to what a form's author called a field. Review the result before relying on it. The evaluation behind the engine is recorded in the repository, not repeated here, so this page does not go stale when the engine changes.

Limits

Known limits

Error codes

Error codeStatusTrigger
invalid_multipart400Request body could not be parsed as multipart/form-data.
missing_pdf400The request does not have exactly one pdf file field.
invalid_parameter400max_pages is not an integer from 1 to 100, or min_confidence is not a number from 0 to 1.
invalid_format400format is not json or pdf.
no_fields400Only with format=pdf: nothing was detected, so there is no PDF to return.
pdf_too_large400The pdf file is over 4 MB.
invalid_pdf400The PDF could not be parsed (corrupt, or not a PDF).
encrypted_pdf400The PDF needs a password we were not given. Send it as the password form field.
decompressed_too_large400Streams inside the PDF decompress to over 32 MB.
too_many_pages400The PDF has over 2,000 pages.
invalid_pages400pages is not a valid page spec or names a page past the end.
request_too_large413The whole request body is over 4.5 MB (Vercel's platform request limit). Rejected before anything is parsed.
invalid_api_key401An X-API-Key header was sent but the key is unknown or revoked. Get a fresh key at /pricing.
rate_limited429The anonymous per-IP limit (100/month) or your key's monthly quota is used up. Retry-After gives seconds until next calendar month.

Examples

Detect on a one-page form (sample-flat-form.pdf), keyless, listing name, type and confidence:

curl -s -X POST https://pdfops.dev/api/detect-fields -F "pdf=@sample-flat-form.pdf" \
  | jq -r '.fields[] | [.type, .name, .confidence] | @tsv'
text	Full name	0.85
text	Date of birth	0.85
text	Address	0.86
text	Phone	0.9
checkbox	Individual	0.9
checkbox	Family	0.9
text	Signature	0.85
text	Date	0.85

Only the checkboxes, and only page 1:

curl -s -X POST https://pdfops.dev/api/detect-fields -F "pdf=@sample-flat-form.pdf" -F "pages=1" \
  | jq -c '[.fields[] | select(.type == "checkbox") | .name]'
["Individual","Family"]

A page with nothing drawn on it:

{"pages":[{"page":1,"width":300,"height":300,"fields":0}],"count":0,"truncated":false,"note":"No fields were found. This looks for blanks that are drawn as lines, boxes, underscores or checkboxes; a form whose blanks are bare space or a scanned image has none to find.","fields":[]}

An encrypted PDF without its password:

{"error":"encrypted_pdf","details":"this PDF is encrypted with a password we could not open. Pass the password that opens it as the `password` form field. (Owner-locked files with an empty user password, which most government blanks are, open without one.)"}

Keyless calls work: 100 requests per IP per month with no key.

Using this for real? A free API key raises the keyless 100 calls per IP to 250 requests a month, with no card.

Get a free API key

Code examples

Have an API key? Add an X-API-Key header to any request. It is optional, and it raises your quota from 100/IP/month to your tier's.

JavaScript (Node.js 22+), built-in fetch + FormData
import { readFile, writeFile } from 'node:fs/promises';

const headers = {};
if (process.env.PDFOPS_API_KEY) headers['X-API-Key'] = process.env.PDFOPS_API_KEY; // optional
const pdf = new Blob([await readFile('sample-flat-form.pdf')], { type: 'application/pdf' });

// 1. detect
let fd = new FormData();
fd.append('pdf', pdf, 'sample-flat-form.pdf');
const det = await fetch('https://pdfops.dev/api/detect-fields', { method: 'POST', headers, body: fd });
if (!det.ok) {
  const err = await det.json();
  throw new Error(`PDFops detect failed: ${err.error}: ${err.details}`);
}
const { fields } = await det.json();

// 2. review: keep the confident ones, then add them (label and confidence are ignored)
const keep = fields.filter((f) => f.confidence >= 0.6);
fd = new FormData();
fd.append('pdf', pdf, 'sample-flat-form.pdf');
fd.append('fields', JSON.stringify(keep));
const res = await fetch('https://pdfops.dev/api/add-fields', { method: 'POST', headers, body: fd });
if (!res.ok) throw new Error(`PDFops add-fields failed: ${(await res.json()).error}`);
await writeFile('fillable.pdf', Buffer.from(await res.arrayBuffer()));
Python with requests
import json, os, requests

headers = {"X-API-Key": os.environ.get("PDFOPS_API_KEY", "")}  # optional

with open("sample-flat-form.pdf", "rb") as pdf:
    res = requests.post("https://pdfops.dev/api/detect-fields", headers=headers, files={"pdf": pdf})
res.raise_for_status()
fields = res.json()["fields"]

# review: keep the confident ones, then add them (label and confidence are ignored)
keep = [f for f in fields if f["confidence"] >= 0.6]
with open("sample-flat-form.pdf", "rb") as pdf:
    res = requests.post(
        "https://pdfops.dev/api/add-fields",
        headers=headers,
        files={"pdf": pdf},
        data={"fields": json.dumps(keep)},
    )
res.raise_for_status()
open("fillable.pdf", "wb").write(res.content)

From an AI agent (MCP)

The hosted MCP server at https://pdfops.dev/api/mcp exposes this as the read-only pdf_detect_fields tool, and pdf_add_fields takes detect: true to do detect and add in one tool call (one request, the format=pdf call above). For a flat PDF with no fillable fields the pattern is: detect, review, then add and fill. Call pdf_detect_fields, drop or rename what is wrong, pass the rest to pdf_add_fields as fields, then fill the result with pdf_fill. See the MCP server page.

Behavioral notes

FAQ

How do I make a flat PDF fillable with an API?

POST the PDF to https://pdfops.dev/api/detect-fields. It returns the blanks drawn on the page as text and checkbox fields with names from nearby labels. Review them, then send the ones you keep to /api/add-fields as fields.

Does it find every field on a form?

No. It finds blanks that are drawn as lines, boxes, underscores and checkboxes. It does not find a field that has nothing drawn, so review the result before relying on it. A blank that is only empty space, or a scanned page, has nothing to detect.

Does it use a model?

No. It applies fixed geometry rules to the page's drawing and text, so it is deterministic, fast (a median of 67 ms per form) and counts as one request.

Can I send the response straight to add-fields?

Yes. Each entry in fields uses the same property names and coordinate frame as the fields input of /api/add-fields. The extra keys label and confidence are ignored there.

What happens on a scanned PDF?

A scanned page is a picture, with no drawn lines and no text to read, so the answer is count: 0 with a note. There is no OCR.

Related: Add fillable fields · List form fields · Fill a form · Make a PDF fillable in the browser.

Get a free API key. Keyless calls get 100 requests per IP per month; a free key raises that to 250, with no card. Enter your email and the key arrives in your inbox.

Get a free API key