Articles on: PDF Services

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 and Fill Form Fields 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


1. Extract Form Fields


The first step is to analyze your fillable PDF to understand its structure. The Extract Form Fields 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



Request Body


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


Response


{
"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 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



Request Body


{
"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.


{
"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



Updated on: 10/09/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!