Add Form Fields to PDF - Interactive Form API
PDF4me Add Form Fields to PDF enables you to add interactive form fields to PDF documents. This API service processes PDF files and adds form fields (text boxes and checkboxes) at specific positions on specified pages. The API receives PDF content and form field parameters through REST API calls, utilizing Base64 encoding for secure transmission. With support for flexible positioning, custom field types, and page targeting, this solution is ideal for document automation and interactive PDF development workflows.
Authenticating Your API Request
To access the PDF4me REST API, every request must include proper authentication credentials. Authentication ensures secure communication and validates your identity as an authorized user of the REST API.
Key Features
- Form Field Types: Add TextBox and CheckBox form fields to PDF documents
- Precise Positioning: Control field placement with exact X and Y coordinates
- Custom Field Sizing: Adjust form field dimensions to match design requirements
- Flexible Page Targeting: Apply form fields to specific pages or entire documents
- Initial Values: Set default values for form fields
- Base64 Encoding: Secure file content transmission using Base64 encoding
- Simple API Integration: RESTful API designed for automated PDF form creation workflows
REST API Endpoint
The PDF4me REST API uses standard HTTP methods to interact with resources. All form field addition operations are performed through a single endpoint:
- Method: POST
- Endpoint:
/api/v2/AddFormField
REST API Parameters
Complete list of parameters for the Add Form Fields To PDF REST API. Parameters are organized by category for better understanding and implementation.
Important: Parameters marked with an asterisk (*) are required and must be provided for the API to function correctly.
Required Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| docContent* | Base64 | The content of the input PDF file encoded in Base64 | JVBERi... |
| docName* | String | Source PDF file name with .pdf extension | output.pdf |
| initialValue* | String | Initial value for the form field | New input text |
| positionX* | Integer | X position of the form field on the page | 300 |
| positionY* | Integer | Y position of the form field on the page | 300 |
| fieldName* | String | Name of the form field | Input Field Name |
| Size* | Integer | Size of the form field | 4 |
| pages* | String | Page options: "1" for page 1, "1,3,5" for specific pages, "2-5" for page range, "1,3,7-10" for mixed, "1-" for pages from 1 to end | 1 |
| formFieldType* | String | Form field type: TextBox or CheckBox | TextBox |
Optional Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| async | Boolean | Enable asynchronous processing. When true, the API returns a 202 status and provides a polling URL in the Location header | true |
Output
The PDF4me Add Form Fields to PDF REST API returns different responses based on the processing mode. The API returns the PDF as binary data for synchronous processing or provides a polling URL for asynchronous processing.
- Success Response
- Asynchronous Processing
- Error Responses
- Response Format Details
Synchronous Processing (Default)
When async is not set or set to false, the API processes the request immediately:
Status Code: 200 OK
Content-Type: application/pdf or application/octet-stream
Response Body:
The API returns the PDF file directly as binary data (not JSON).
How to Use:
- The response body contains the binary PDF data
- Save the response content directly as a PDF file
- No Base64 decoding is needed for binary responses
Example (JavaScript):
const response = await fetch(url, options);
const pdfBlob = await response.blob();
// Save or process pdfBlob directly
Asynchronous Processing
When async: true is set, the API processes the request asynchronously:
Status Code: 202 Accepted
Response Headers:
Location: https://api.pdf4me.com/api/v2/AddFormField/poll/12345-abcde-67890
Polling Process:
- Extract the
Locationheader from the 202 response - Poll the URL using GET requests
- Continue polling until you receive a 200 OK status
- The final response contains the binary PDF data
Polling Example:
// Initial request returns 202 with Location header
const response = await fetch(url, options);
const location = response.headers.get('Location');
// Poll until complete
while (true) {
const pollResponse = await fetch(location, { headers: { 'Authorization': 'Basic ' + apiKey } });
if (pollResponse.status === 200) {
const pdfBlob = await pollResponse.blob();
// Process binary PDF
break;
}
await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
}
Error Responses
| Status Code | Description | Example Response |
|---|---|---|
| 400 Bad Request | Invalid request parameters or missing required fields | {"error": "Missing required parameter: fieldName"} |
| 401 Unauthorized | Invalid or missing API key | {"error": "Unauthorized"} |
| 500 Internal Server Error | Server error during processing | {"error": "Internal server error"} |
Understanding the Response
- Synchronous (200): Returns binary PDF data directly
- Asynchronous (202): Returns Location header for polling, final response is binary PDF
- No JSON Wrapper: The API returns PDF as binary, not wrapped in JSON with Base64 encoding
Request Example
Header
Content-Type: application/json
Authorization: Basic YOUR_BASE64_ENCODED_API_KEY
Note: The API key must be Base64 encoded. Get your API key from the PDF4me Dashboard
Payload
{
"docContent": "Please put PDF base64 content",
"docName": "output.pdf",
"initialValue": "input text",
"positionX": 300,
"positionY": 300,
"fieldName": "Input Field Name",
"Size": 4,
"pages": "1",
"formFieldType": "TextBox"
}
Code Samples
The PDF4me Add Form Fields To PDF REST API provides code samples in multiple programming languages. Choose the language that best fits your development environment:
- C#
- Java
- JavaScript
- Python
- Salesforce
- n8n
- Google Script
- AWS Lambda
Google Script Sample
Google Apps Script implementation for Google Workspace integration:
Form Field Creation Features
Form Field Types
- TextBox Fields: Create text input fields for user data entry and form completion
- CheckBox Fields: Add checkbox elements for selection and confirmation options
- Custom Sizing: Adjust field dimensions to match design requirements and content needs
- Professional Results: High-quality form field creation with accurate functionality
- Advanced Processing: Support for complex form layouts and field arrangements
Positioning and Layout
- Precise Coordinates: Control field placement with exact X and Y position values
- Flexible Positioning: Support for any page position and field arrangement
- Page Targeting: Apply form fields to specific pages or entire documents
- Custom Sizing: Adjustable field dimensions for optimal form design
- Professional Layout: Consistent form field placement across all target pages
Advanced Features
- Initial Values: Set default field values for improved user experience
- Field Naming: Custom field names for form data collection and processing
- Professional Creation: High-quality form field generation with clear functionality
- Flexible Options: Customizable form field parameters for specific requirements
Industry Use Cases & Applications
- Legal & Professional Services
- Healthcare & Medical
- Finance & Banking
- Human Resources
- Business & Enterprise
Legal & Professional Services Use Cases
- Contract Forms: Add form fields to contracts and agreements for digital signatures
- Legal Documentation: Create interactive forms for legal document processing
- Compliance Forms: Build forms for regulatory compliance and documentation
- Client Intake: Create client intake forms for legal services
Healthcare & Medical Use Cases
- Patient Forms: Create interactive patient intake and medical history forms
- Medical Documentation: Build forms for medical records and documentation
- Insurance Claims: Design forms for insurance claim processing
- Consent Forms: Create consent and authorization forms for medical procedures
Finance & Banking Use Cases
- Financial Applications: Build loan and credit application forms
- Account Opening: Create forms for account opening and KYC processes
- Transaction Forms: Design forms for financial transactions and processing
- Compliance Documentation: Create forms for regulatory compliance reporting
Human Resources Use Cases
- Application Processing: Build application forms for job applications and registrations
- Employee Onboarding: Create forms for employee onboarding and documentation
- Survey Creation: Design interactive surveys and questionnaires in PDF format
- Performance Reviews: Build forms for performance evaluation and feedback
Business & Enterprise Use Cases
- Document Automation: Create interactive forms for data collection and processing
- Data Collection: Create forms for gathering customer information and feedback
- Interactive Documents: Add form fields to existing PDFs for enhanced user engagement
- Business Process Automation: Create forms for automated business workflows and data entry