> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://support.pdfgeneratorapi.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Extract and Fill Existing PDF Forms Programmatically

Extracting and filling form fields in PDFs allows you to automate working with interactive documents. Using our API’s [Extract Form Fields](https://docs.pdfgeneratorapi.com/v4/#tag/Services/operation/extractFormFields) and [Fill Form Fields](https://docs.pdfgeneratorapi.com/v4/#tag/Services/operation/fillFormFields) endpoints, you can easily retrieve editable fields from existing PDFs and populate them with dynamic data, streamlining workflows and improving efficiency.
---

In this tutorial, we’ll use an editable KYC (Know Your Customer) form to demonstrate how extraction and filling works.

![Editable PDF Form](https://storage.crisp.chat/users/helpdesk/website/-/1/1/e/0/11e0e518fc48ce00/editablekyc_vc6wij.png)
---

### 1. Extract Form Fields

The first step is to analyze your fillable PDF to understand its structure. The [Extract Form Fields](https://docs.pdfgeneratorapi.com/v4/#tag/Services/operation/extractFormFields) endpoint takes either a file URL or a base64 string and returns a structured JSON containing all available fields. For each field you will get:

* **Unique field name** – used as the key when filling data.
* **Field type** – e.g., `textfield`, `checkbox`.
* **Current value** – if the PDF already contains pre-filled data.
* **Metadata** – includes information such as field ID, page number, lock state, or whether a field supports multiple lines of input.

|| If an editable field in the PDF doesn't have a predefined name, the API will assign a randomly generated one, for example: Text-68bea15d1181a68bea15d15ea5

#### Endpoint Details

* **HTTP Method:** `POST`
* **Request URL:** `https://us1.pdfgeneratorapi.com/api/v4/pdfservices/form/fields`
* **Documentation:** [Official API Docs](https://docs.pdfgeneratorapi.com/v4#tag/Services/operation/extractFormFields)

###### Request Body

```json
{"file_url": "https://us1.pdfgeneratorapi.com/api/v4/documents/66/97e0434f37..."}
```

###### Response

```json
{
    "response": {
        "contact_address": {
            "id": "17",
            "type": "textfield",
            "name": "contact_address",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "country_of_birth": {
            "id": "28",
            "type": "textfield",
            "name": "country_of_birth",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "date_of_birth": {
            "id": "27",
            "type": "textfield",
            "name": "date_of_birth",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "document_number": {
            "id": "19",
            "type": "textfield",
            "name": "document_number",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "email": {
            "id": "30",
            "type": "textfield",
            "name": "email",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "first_name": {
            "id": "24",
            "type": "textfield",
            "name": "first_name",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "identity_document": {
            "id": "18",
            "type": "textfield",
            "name": "identity_document",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "issued_on": {
            "id": "22",
            "type": "textfield",
            "name": "issued_on",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "issuing_country": {
            "id": "21",
            "type": "textfield",
            "name": "issuing_country",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "last_name": {
            "id": "25",
            "type": "textfield",
            "name": "last_name",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "nationality": {
            "id": "29",
            "type": "textfield",
            "name": "nationality",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "other_countries": {
            "id": "16",
            "type": "textfield",
            "name": "other_countries",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "phone": {
            "id": "31",
            "type": "textfield",
            "name": "phone",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "pic": {
            "id": "26",
            "type": "textfield",
            "name": "pic",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "residence_address": {
            "id": "23",
            "type": "textfield",
            "name": "residence_address",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "tax_confirmation": {
            "id": "15",
            "type": "checkbox",
            "name": "tax_confirmation",
            "locked": false,
            "pages": [
                1
            ],
            "value": true,
            "default": false
        },
        "tax_residency": {
            "id": "14",
            "type": "textfield",
            "name": "tax_residency",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        },
        "valid_until": {
            "id": "20",
            "type": "textfield",
            "name": "valid_until",
            "locked": false,
            "pages": [
                1
            ],
            "value": "\n\n",
            "multiline": true
        }
    }
}
```

---

### 2. Fill Form Fields

Once you know which fields are available, you can move on to filling them with actual data. The [Fill Form Fields](https://docs.pdfgeneratorapi.com/v4/#tag/Services/operation/fillFormFields) endpoint accepts the same file URL or base64 string together with key-value pairs matching the extracted field names. In return, you receive a fully populated PDF that can be downloaded or shared immediately.

#### Endpoint Details

* **HTTP Method:** `POST`
* **Request URL:** `https://us1.pdfgeneratorapi.com/api/v4/pdfservices/form/fill`
* **Documentation:** [Official API Docs](https://docs.pdfgeneratorapi.com/v4#tag/Services/operation/fillFormFields)

###### Request Body

```json
{
  "file_url": "https://us1.pdfgeneratorapi.com/api/v4/documents/66/97e0434f37...",
  "data":{
    "contact_address": "123 Main Street, New York, NY 10001, USA",
    "country_of_birth": "United States",
    "date_of_birth": "1985-07-14",
    "document_number": "X1234567",
    "email": "john.doe@example.com",
    "first_name": "John",
    "identity_document": "Passport",
    "issued_on": "2015-06-01",
    "issuing_country": "United States",
    "last_name": "Doe",
    "nationality": "American",
    "other_countries": "Canada, Germany",
    "phone": "+1 000 000 0000",
    "pic": "123456",
    "residence_address": "456 Elm Street, Los Angeles, CA 90001, USA",
    "tax_confirmation": true,
    "tax_residency": "United States",
    "valid_until": "2025-06-01"
},
  "output": "url",
  "name": "KYC_Form"
}
```

###### Response

The response field contains a direct URL to the generated, filled PDF form.

```json
{
    "response": "https://us1.pdfgeneratorapi.com/api/v4/documents/66/d83e7f0104...",
    "meta": {
        "name": "KYC_Form.pdf",
        "display_name": "KYC_Form",
        "encoding": "binary",
        "content-type": "application/pdf",
        "public_id": "41905c77709c9b5ba42946491c8942b0"
    }
}
```

![PDF Form Filled via API](https://storage.crisp.chat/users/helpdesk/website/-/1/1/e/0/11e0e518fc48ce00/editablekycfilled_1r7g6vg.png)

---
### Related articles you may find helpful

* [Converting HTML to PDF - How to start?](/en/article/converting-html-to-pdf-how-to-start-1t3jshu/)
* [How to Create a Form](/en/article/how-to-create-a-form-152rrmx/)
* [Is it possible to deploy PDF Generator API on premises (on-prem) or have dedicated infrastructure?](/en/article/is-it-possible-to-deploy-pdf-generator-api-on-premises-on-prem-or-have-dedicated-infrastructure-17ockzt/)