This instructional article will take you through the step-by-step process of filling out PDF Form 1040 using PDF.co Web API with cURL.

  1. Get API Key and Get the List of PDF Form Fields
  2. Copy and Paste Code and Add API Key
  3. Use pdf/edit/add Endpoint to Fill Form
  4. Copy and Paste Code and Add API Key (2)
  5. See Result

Useful resources:

For this example, we will use IRS Form 1040

IRS Form F1040

1. Get API Key and Get the List of PDF Form Fields

  • Sign up and get your API key on https://app.pdf.co/signup
  • Use /pdf/info/fields endpoint to get the list of all fields in this PDF form

2. Copy and Paste this Code and Add Your API Key:

curl --location --request GET 'https://api.pdf.co/v1/pdf/info/fields?url=https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-form/f1040.pdf' \
--header 'x-api-key: YOUR_API_KEY_HERE'

It will return all the form fields information like this:

PDF Form Fields Result

3. Use pdf/edit/add Endpoint to Fill Form

Now that we have a list of all fields. We can use /pdf/edit/add endpoint to fill them out.

4. Copy and Paste this Code and Add Your API Key:

curl --location --request POST 'https://api.pdf.co/v1/pdf/edit/add' \
--header 'Content-Type: application/json' \
--header 'x-api-key: YOUR_API_KEY_HERE' \
--data-raw '{
"async": false,
"encrypt": false,
"name": "f1040-filled",
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-form/f1040.pdf",
"fields": [
{
"fieldName": "topmostSubform[0].Page1[0].FilingStatus[0].c1_01[1]",
"pages": "1",
"text": "True"
},
{
"fieldName": "topmostSubform[0].Page1[0].f1_02[0]",
"pages": "1",
"text": "John A."
},
{
"fieldName": "topmostSubform[0].Page1[0].f1_03[0]",
"pages": "1",
"text": "Doe"
},
{
"fieldName": "topmostSubform[0].Page1[0].YourSocial_ReadOrderControl[0].f1_04[0]",
"pages": "1",
"text": "123456789"
},
{
"fieldName": "topmostSubform[0].Page1[0].YourSocial_ReadOrderControl[0].f1_05[0]",
"pages": "1",
"text": "Joan B."
},
{
"fieldName": "topmostSubform[0].Page1[0].YourSocial_ReadOrderControl[0].f1_05[0]",
"pages": "1",
"text": "Joan B."
},
{
"fieldName": "topmostSubform[0].Page1[0].YourSocial_ReadOrderControl[0].f1_06[0]",
"pages": "1",
"text": "Doe"
},
{
"fieldName": "topmostSubform[0].Page1[0].YourSocial_ReadOrderControl[0].f1_07[0]",
"pages": "1",
"text": "987654321"
}

],
“annotations”:[
{
“text”:”Sample Filled with PDF.co API using /pdf/edit/add. Get fields from forms using /pdf/info/fields”,
“x”: 10,
“y”: 10,
“size”: 12,
“pages”: “0-“,
“color”: “FFCCCC”,
“link”: “https://pdf.co”
}
],
“images”: [
]
}’

5. See Result

Copy and paste the resulting URL on your browser to see your filled-out PDF form.

cURL PDF Form 1040 Result URL

The filled-out IRS PDF Form will look like this:

Filled-Out IRS F1040 PDF Form

Note: The output URL expires in 1 hour. You may need to generate a new URL once 1 hour has elapsed.

Related Pages:

Related Samples: