# PDF Form Extractor & Filler (AcroForm to JSON, Fill & Flatten) (`freecamp008/pdf-form-extractor`) Actor

Extract every fillable PDF form field (name, type, value, options, page, position) to JSON, or fill PDF forms from a JSON map and download the filled or flattened PDF. Detects XFA forms and extracts XFA data. No external APIs.

- **URL**: https://apify.com/freecamp008/pdf-form-extractor.md
- **Developed by:** [Camp8 fr0](https://apify.com/freecamp008) (community)
- **Categories:** Developer tools, Automation, AI
- **Features:** Limited permissions, Single-tenant, Server interface
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $4.00 / 1,000 form processeds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## PDF Form Extractor & Filler – Fillable PDF (AcroForm) to JSON, Fill & Flatten PDF Forms

**PDF Form Extractor & Filler** reads every fillable field of a PDF form (text boxes, checkboxes, radio buttons, dropdowns, list boxes, signatures) and returns it as clean JSON: **name, type, current value, options, page and position**. In **fill mode** it does the opposite: give it a JSON object of values and get back the **filled PDF**, optionally **flattened** so it can no longer be edited. XFA (LiveCycle) forms are detected and their data is extracted. Everything runs inside the Actor: no external APIs, and your documents never leave Apify.

### What does PDF Form Extractor & Filler do?

- 📋 **Extracts all AcroForm fields**: full name, short name, tooltip, type, value, default value, options (with export values and labels), required / read-only / hidden flags, max length, comb and multiline flags.
- 📍 **Field positions**: page number and rectangle (points, top-left origin) of every widget, ideal for overlays, form-building UIs and document AI training data.
- 🧾 **`values` map**: a ready-to-edit `{ "field name": value }` object you can send straight back in fill mode.
- ✍️ **Fill mode**: text, checkboxes, radio groups, dropdowns and multi-select list boxes, matched by full name, short name (e.g. `f1_01`) or tooltip, case-insensitive.
- 🔤 **Unicode values**: Polish, Czech, Greek, Cyrillic, Vietnamese and other non-Latin-1 text is rendered with an embedded Noto Sans font instead of garbled characters.
- 🧱 **Flatten**: burn the values into the page so the PDF looks identical everywhere and cannot be changed.
- ✅ **Verified output**: the filled PDF is re-read with an independent parser and every filled value is compared (`verification.mismatches`).
- 🧬 **XFA aware**: reports hybrid vs. pure XFA forms, extracts the XFA `datasets` values, and removes the stale XFA layer when filling so Acrobat shows your values.
- 🔐 **Encrypted PDFs** supported with a password.
- 🌐 **HTTP API (Standby mode)** with optional base64 output of the filled PDF.

### Use cases

- **Read submitted forms** (applications, onboarding, claims, tax and HR forms) into a database or spreadsheet
- **Auto-fill government and insurance forms** (IRS W-9 / 1040, CERFA, visa and permit forms) from your CRM or ERP
- **Generate many personalised PDFs** from one template (contracts, certificates, invoices)
- Build **form-mapping and document AI** pipelines that need field positions
- **Audit forms**: find required, read-only or hidden fields and their options

### How to use it

1. Click **Try for free** and paste one or more **PDF URLs**.
2. **Extract**: leave Mode = *Extract* and click **Start**. Each PDF becomes one row with `fields` and a `values` map.
3. **Fill**: switch Mode to *Fill*, paste a JSON object into **Fill data** (copy the `values` object from an extract run and edit it), optionally enable **Flatten**, and click **Start**. The filled PDF link is in `outputUrl`.

#### Call it as an HTTP API (Standby mode)

```bash
## Extract fields (GET)
curl "https://<your-standby-url>/?pdfUrls=https://example.com/form.pdf" \
  -H "Authorization: Bearer <APIFY_TOKEN>"

## Fill + flatten (POST), filled PDF inline as base64
curl -X POST "https://<your-standby-url>/" \
  -H "Authorization: Bearer <APIFY_TOKEN>" -H "Content-Type: application/json" \
  -d '{"mode":"fill","pdfUrls":["https://example.com/form.pdf"],"fillData":{"Name":"Jane Doe","Agree":true},"flatten":true,"returnBase64":true}'
```

Response: `{ "count": 1, "items": [ ... ] }`

You can also use the Apify API (`run-sync-get-dataset-items`), the Apify MCP server, Make, Zapier, n8n and other integrations. **AI agents can pay per call with x402 (USDC)** through Apify's agentic payments, without needing an Apify account.

### Input example

```json
{
  "pdfUrls": ["https://raw.githubusercontent.com/Hopding/pdf-lib/master/assets/pdfs/dod_character.pdf"],
  "mode": "fill",
  "fillData": { "CharacterName 2": "Elara Moonwhisper", "Age": "112", "Backstory": "Line one\nLine two" },
  "flatten": true
}
```

| Field | Description |
|---|---|
| `pdfUrls` | Direct links to PDF forms (also `data:application/pdf;base64,...`) |
| `mode` | `extract` (default) or `fill` |
| `fillData` | Fill mode: `{ "field name": value }`. Text: string. Checkbox: `true`/`false`. Radio / dropdown: option value or label. List box: array |
| `flatten` | Fill mode: make the result non-editable |
| `includeXfaData` | Extract mode: return XFA data values when present (default true) |
| `password` | Password for encrypted PDFs |
| `returnBase64` | Standby API, fill mode: include the filled PDF as base64 |

### Output example

Extract mode (shortened):

```json
{
  "pdfUrl": "https://raw.githubusercontent.com/Hopding/pdf-lib/master/assets/pdfs/with_xfa_fields.pdf",
  "mode": "extract",
  "pageCount": 2,
  "hasAcroForm": true,
  "fieldCount": 116,
  "xfa": {
    "present": true,
    "pureXfa": false,
    "packets": ["xdp:xdp", "config", "template", "datasets", "sourceSet", "connectionSet", "localeSet", "xmpmeta", "xfdf", "form", "</xdp:xdp>"],
    "values": { "topmostSubform.ReadOrderControl[1].PresidentialElection.c1_02": "0" }
  },
  "values": { "topmostSubform[0].Page1[0].FilingStatus[0].c1_01[0]": false, "topmostSubform[0].Page1[0].FilingStatus[0].f1_01[0]": "" },
  "fields": [
    { "name": "topmostSubform[0].Page1[0].FilingStatus[0].c1_01[0]", "shortName": "c1_01[0]", "type": "checkbox", "exportValue": "1", "value": false, "defaultValue": "Off", "page": 1, "rect": { "left": 95.6, "top": 68, "width": 8, "height": 8 } },
    { "name": "topmostSubform[0].Page1[0].FilingStatus[0].f1_01[0]", "shortName": "f1_01[0]", "type": "text", "value": "", "page": 1, "rect": { "left": 208.8, "top": 90, "width": 331.2, "height": 12 } }
  ]
}
```

Fill mode (shortened):

```json
{
  "pdfUrl": "https://raw.githubusercontent.com/Hopding/pdf-lib/master/assets/pdfs/dod_character.pdf",
  "mode": "fill",
  "outputUrl": "https://api.apify.com/v2/key-value-stores/<storeId>/records/dod_character-c72a8a27ced4-filled",
  "flattened": true,
  "fieldCount": 14,
  "filledCount": 3,
  "filled": [{ "key": "Age", "field": "Age", "type": "text", "value": "112" }],
  "failed": [],
  "notFound": [],
  "warnings": [],
  "verification": { "flattened": true, "remainingFields": 0 }
}
```

### Pricing

This Actor uses **pay-per-event** pricing:

| Event | Price |
|---|---|
| Form processed (extract or fill, per PDF) | **$4 per 1,000 forms** ($0.004 each) |

Download errors, broken PDFs, PDFs without form fields in fill mode, and fills where no key matched any field are free. Apify platform usage (compute) is billed separately and is typically a fraction of a cent per form. Set **Maximum cost per run** to cap your spend.

### FAQ

**How do I find the field names to fill?**
Run extract mode once. Use the `name` of each field, or simply copy the `values` object, change the values, and paste it as `fillData`. Short names (`f1_01` instead of `topmostSubform[0].Page1[0].f1_01[0]`) and tooltips also work when they are unique.

**What about XFA / LiveCycle forms?**
Hybrid forms (most IRS and government forms) contain both AcroForm and XFA: all fields are extracted and can be filled; the XFA layer is removed on fill so viewers show the AcroForm values. Pure (dynamic) XFA forms have no AcroForm fields: the Actor reports `pureXfa: true` and returns the XFA data values, but cannot fill them.

**Does it work on scanned paper forms or PDFs without fields?**
No. It reads the interactive form layer. Flat PDFs and scans have no fields (the result says so and fill mode is not charged).

**Which languages and characters are supported when filling?**
Latin-1 text uses Helvetica. Any value outside Latin-1 (Polish, Czech, Greek, Cyrillic, Vietnamese...) automatically switches the field to an embedded Noto Sans font. Chinese/Japanese/Korean glyphs and right-to-left shaping (Arabic, Hebrew) are not covered by that font.

**Can it sign forms?**
No. Signature fields are listed (with `signed`), but digital signing is out of scope.

**Is the output encrypted if the input was?**
No. Encrypted inputs are decrypted with your password and the filled PDF is saved without encryption.

**Is my data private?**
Files are processed inside your Apify run and stored only in your run's key-value store. Nothing is sent to third-party services.

**Licenses?**
pdf.js (Apache-2.0), @cantoo/pdf-lib (MIT), @pdf-lib/fontkit (MIT), Noto Sans font (SIL Open Font License 1.1). All allow commercial use.

# Actor input Schema

## `pdfUrls` (type: `array`):

Direct links to fillable PDF forms (or <code>data:application/pdf;base64,...</code> URLs). Each PDF becomes one result.

## `mode` (type: `string`):

<b>extract</b>: list every form field with its type, current value, options, page and position. <b>fill</b>: fill the fields from <b>Fill data</b> and return the filled PDF.

## `fillData` (type: `object`):

Fill mode: a JSON object mapping field names to values, e.g. <code>{"Name": "Jane Doe", "Agree": true, "Country": "France"}</code>. Use the <code>name</code> values from an extract run; short names (last part of the name) and tooltips also match. Checkboxes take true/false, radio groups and dropdowns take an option value, list boxes accept an array.

## `flatten` (type: `boolean`):

Fill mode: merge the filled values into the page content so the result is no longer editable (recommended for archiving and sending).

## `includeXfaData` (type: `boolean`):

Extract mode: if the PDF contains an XFA (LiveCycle) form, also return the values stored in its XFA data packet as key-value pairs.

## `password` (type: `string`):

Password for encrypted PDFs (optional).

## `returnBase64` (type: `boolean`):

Standby HTTP API only, fill mode: also include the filled PDF as a base64 string (<code>pdfBase64</code>) in the response.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://raw.githubusercontent.com/Hopding/pdf-lib/master/assets/pdfs/with_xfa_fields.pdf"
  ],
  "mode": "extract",
  "fillData": {
    "CharacterName 2": "Elara Moonwhisper",
    "Age": "112",
    "Height": "5'7\""
  },
  "flatten": false,
  "includeXfaData": true,
  "returnBase64": false
}
```

# Actor output Schema

## `forms` (type: `string`):

No description

## `files` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "pdfUrls": [
        "https://raw.githubusercontent.com/Hopding/pdf-lib/master/assets/pdfs/dod_character.pdf",
        "https://raw.githubusercontent.com/Hopding/pdf-lib/master/assets/pdfs/with_xfa_fields.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("freecamp008/pdf-form-extractor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "pdfUrls": [
        "https://raw.githubusercontent.com/Hopding/pdf-lib/master/assets/pdfs/dod_character.pdf",
        "https://raw.githubusercontent.com/Hopding/pdf-lib/master/assets/pdfs/with_xfa_fields.pdf",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("freecamp008/pdf-form-extractor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "pdfUrls": [
    "https://raw.githubusercontent.com/Hopding/pdf-lib/master/assets/pdfs/dod_character.pdf",
    "https://raw.githubusercontent.com/Hopding/pdf-lib/master/assets/pdfs/with_xfa_fields.pdf"
  ]
}' |
apify call freecamp008/pdf-form-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,freecamp008/pdf-form-extractor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/71lpledEhGRhetxjF/builds/R92PmZuFY1mGiI0AM/openapi.json
