Request
Request Body
file
filerequiredPDF file to process with form fields to be filled
Maximum 10MB, PDF format only
data
stringoptionalText containing information to fill form fields (any format)
Example formats (all are valid):
// Structured format:
Name: John Doe
Email: [email protected]
Phone: +1-555-123-4567
Address: 123 Main St, New York, NY 10001
// Unstructured format:
"I'm John Doe, living at 123 Main St in New York.
My email is [email protected] and phone is +1-555-123-4567."
// Mixed format:
John Doe | [email protected]
123 Main St, New York, NY 10001
Phone: (555) 123-4567
curl --request POST \
--url https://pdfmage.app/api/v1/fill-pdf \
--header 'Accept: application/pdf' \
--header 'Authorization: Bearer pk_live_abc123...' \
--form 'file=@/path/to/form.pdf' \
--form 'data="John Doe, [email protected], +1-555-123-4567, 123 Main St, New York, NY 10001"'
const formData = new FormData();
formData.append('file', pdfFile);
formData.append('data', `
Name: John Doe
Email: [email protected]
Phone: +1-555-123-4567
Address: 123 Main St, New York, NY 10001
`);
const response = await fetch('https://pdfmage.app/api/v1/fill-pdf', {
method: 'POST',
headers: {
'Authorization': 'Bearer pk_live_abc123...'
},
body: formData
});
if (response.ok) {
const filledPdf = await response.blob();
// Save or display the filled PDF
} else {
const error = await response.json();
console.error('Error:', error);
}
Response
Response Body
body
binaryBinary PDF file content with filled form fields
Response Headers
Content-Type
string - application/pdfContent-Disposition
string - attachment; filename="filled-document.pdf"X-Processing-Stats
string - JSON string with processing statisticsX-Credits-Used
number - Credits deducted for this operationX-Credits-Remaining
number - Remaining credit balanceX-Credits-Currency
string - Currency of credits (USD)HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Disposition: attachment; filename="filled-document.pdf"
Content-Length: 1048576
X-Processing-Stats: {"processingTime":1247,"confidence":0.95}
X-Credits-Used: 0.02
X-Credits-Remaining: 4.98
X-Credits-Currency: USD
[Binary PDF Content]
// X-Processing-Stats header contains:
{
"timing": {
"fieldExtraction": 120, // Field extraction time (ms)
"textExtraction": 450, // OCR processing time (ms)
"fieldMapping": 230, // Field mapping time (ms)
"fieldFilling": 180, // Field filling time (ms)
"pdfGeneration": 267, // PDF generation time (ms)
"total": 1247 // Total processing time (ms)
}
}
Error Responses
Bad Request
Invalid file format, missing file, or malformed data parameter
Unauthorized
Invalid or missing API key
Payment Required
Insufficient credit balance
Payload Too Large
File exceeds maximum size limit (10MB)
Unprocessable Entity
PDF has no fillable form fields or is corrupted
{
"error": "Insufficient balance",
"message": "Not enough credits to process this request",
"details": {
"code": "INSUFFICIENT_BALANCE",
"amountRequired": 0.02,
"currentBalance": 0.01,
"pageCount": 1
},
"timestamp": "2024-01-15T10:30:00Z",
"requestId": "req_abc123"
}
{
"error": "Bad Request",
"message": "Invalid file format",
"details": {
"code": "INVALID_FILE_FORMAT",
"allowedFormats": ["pdf"],
"receivedFormat": "docx"
},
"timestamp": "2024-01-15T10:30:00Z",
"requestId": "req_def456"
}
Processing Flow
1. Field Extraction
Extract all fillable form fields from the PDF
2. OCR Processing
Extract text content using Google Document AI
3. Field Mapping
AI maps your data to the appropriate form fields
4. PDF Generation
Generate the filled PDF with all form fields populated
Processing typically takes 1-3 seconds
The entire pipeline is optimized for speed while maintaining high accuracy. Processing time depends on document complexity and number of form fields.