Sign PDF - Digital Signature API
PDF4me Sign PDF enables you to add signature images to PDF documents with control over position, size, and appearance. This API service processes PDF files and adds signature images using Base64 encoding for secure transmission. The API receives PDF content and signature image data through REST API calls. This solution is ideal for document authentication, legal compliance, business workflows, and adding visual signatures to documents.
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
- Image Signature Support: Add custom signature images to PDF documents with full control over positioning and sizing
- Flexible Positioning: Control horizontal and vertical alignment with pixel-perfect accuracy
- Custom Sizing: Adjust signature dimensions using both millimeter and pixel measurements
- Advanced Formatting: Set opacity, margins, and background options for professional appearance
- Page Targeting: Apply signatures to specific pages or entire documents
- Print Control: Configure signatures to appear only in print or on screen
- Professional Results: Create signatures that enhance document authentication and security
- Asynchronous Processing: Support for async processing with polling for long-running operations
REST API Endpoint
The PDF4me REST API uses standard HTTP methods to interact with resources. All PDF signing operations are performed through a single endpoint:
- Method: POST
- Endpoint:
/api/v2/SignPdf
Supported PDF Signing Features
The API provides comprehensive support for various PDF signing capabilities:
Signature Image Support
- Common Formats: Support for JPG, PNG, and other standard image formats
- Base64 Encoding: Secure signature transmission through Base64 encoding
- Flexible Sizing: Both millimeter (10-200mm) and pixel (20-600px) based sizing options
- Quality Preservation: Maintains signature image quality in PDF output
Positioning and Layout
- Horizontal Alignment: Left, Center, and Right positioning options
- Vertical Alignment: Top, Middle, and Bottom placement control
- Margin Control: Precise positioning with both millimeter (0-100mm) and pixel (0-300px) based measurements
- Flexible Placement: Support for any page position with exact measurements
- Page Targeting: Apply to specific pages or entire documents (optional)
Advanced Features
- Opacity Control: Adjustable transparency (0-100) for subtle or prominent signatures
- Background Mode: Option to place signatures behind or in front of content
- Print Control: Configure signatures to appear in view and print or print only
- Professional Appearance: High-quality signature rendering with clear visibility
REST API Parameters
Complete list of parameters for the Sign 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 |
|---|---|---|---|
| docName* | String | Output PDF file name with .pdf extension | output.pdf |
| docContent* | Base64 | PDF file content encoded in Base64 | JVBERi... |
| imageFile* | Base64 | Signature image file content encoded in Base64 | iVBORw0KGgoAAAANSUhEUgAA... |
| imageName* | String | Signature image file name with extension (e.g., .jpg, .png) | signature.jpg |
| alignX* | String | Horizontal alignment: Left, Center, or Right | Right |
| alignY* | String | Vertical alignment: Top, Middle, or Bottom | Bottom |
Optional Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| pages | String | Page options: "1", "1,3,5", "2-5", "1,3,7-10", "2-". If not specified, applies to all pages | 1-3 |
| widthInMM | String | Signature width in millimeters (10-200) | 50 |
| heightInMM | String | Signature height in millimeters (10-200) | 25 |
| widthInPx | String | Signature width in pixels (20-600) | 142 |
| heightInPx | String | Signature height in pixels (20-600) | 71 |
| marginXInMM | String | Horizontal margin in millimeters (0-100) | 20 |
| marginYInMM | String | Vertical margin in millimeters (0-100) | 20 |
| marginXInPx | String | Horizontal margin in pixels (0-300) | 57 |
| marginYInPx | String | Vertical margin in pixels (0-300) | 57 |
| opacity | String | Opacity (0-100): 0=invisible, 100=fully opaque | 100 |
| showOnlyInPrint | Boolean | Show signature in view and print (true) or print only (false) | true |
| isBackground | Boolean | Place signature in background (true) or foreground (false) | false |
| 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 Sign PDF REST API returns different responses based on the processing mode. The API returns the PDF as a Base64-encoded string in JSON format, not as binary data.
- 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/json
Response Body:
{
"docName": "output.pdf",
"docContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPD4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZG9iago1IDAgb2JqCjw8Ci9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihIZWxsbyBXb3JsZCkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1NCAwMDAwMCBuIAowMDAwMDAwMTAxIDAwMDAwIG4gCjAwMDAwMDAxNzAgMDAwMDAgbiAKMDAwMDAwMDI0NCAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjM0MQolJUVPRg=="
}
Response Fields:
- docName (string): The output PDF file name
- docContent (string): The PDF file with signature added, encoded as Base64 string
How to Use:
- Extract the
docContentfield from the JSON response - Decode the Base64 string to get the binary PDF data
- Save or process the PDF file as needed
Example (JavaScript):
const response = await fetch(url, options);
const data = await response.json();
const pdfBytes = atob(data.docContent); // Decode Base64
// Save or process pdfBytes
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/SignPdf/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 same JSON format with
docNameanddocContent(Base64)
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 data = await pollResponse.json();
// Process data.docContent (Base64 PDF)
break;
}
await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
}
Error Responses
The API returns standard HTTP error codes with error details:
- Invalid request parameters
- Missing required fields (
docContent,docName,imageFile,imageName,alignX,alignY) - Invalid Base64 encoding in
docContentorimageFile - Invalid alignment values (must be "Left", "Center", "Right" for alignX; "Top", "Middle", "Bottom" for alignY)
- Invalid size values (width/height must be within specified ranges)
- Invalid opacity value (must be between 0-100)
- Invalid or missing API key
- API key not properly Base64 encoded in Authorization header
- Missing
Authorization: Basicheader
- Server-side processing error
- PDF processing failure
- Signature addition failure
Error Response Format:
{
"error": "Error message describing what went wrong"
}
Response Format Details
Important: The API always returns JSON, never binary PDF data directly.
Response Structure:
{
"docName": "string", // Output PDF filename
"docContent": "string" // Base64-encoded PDF content
}
Content-Type Header:
- Success:
application/json - The PDF is embedded as a Base64 string within the JSON response
Why Base64?
- JSON-safe encoding for binary data
- Easy to transmit over HTTP
- Compatible with all programming languages
- Can be directly embedded in JSON without escaping issues
Decoding Base64 to PDF:
JavaScript/Node.js:
const base64 = response.docContent;
const binary = atob(base64); // Browser
// OR
const binary = Buffer.from(base64, 'base64').toString('binary'); // Node.js
Python:
import base64
pdf_bytes = base64.b64decode(response['docContent'])
with open('output.pdf', 'wb') as f:
f.write(pdf_bytes)
C#:
byte[] pdfBytes = Convert.FromBase64String(response.docContent);
File.WriteAllBytes("output.pdf", pdfBytes);
Request Example
Header
Content-Type: application/json
Authorization: Basic YOUR_BASE64_ENCODED_API_KEY
Note:
- Get your API key from the PDF4me Dashboard
- The API key must be Base64 encoded and prefixed with "Basic " in the Authorization header
- Example: If your API key is
abc123, encode it to Base64 and useAuthorization: Basic YWJjMTIz
Payload
Basic Example (Required Fields Only):
{
"docName": "output.pdf",
"docContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPD4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZG9iago1IDAgb2JqCjw8Ci9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihIZWxsbyBXb3JsZCkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1NCAwMDAwMCBuIAowMDAwMDAwMTAxIDAwMDAwIG4gCjAwMDAwMDAxNzAgMDAwMDAgbiAKMDAwMDAwMDI0NCAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjM0MQolJUVPRg==",
"imageFile": "iVBORw0KGgoAAAANSUhEUgAA...",
"imageName": "signature.jpg",
"alignX": "Right",
"alignY": "Bottom"
}
Advanced Example (With All Optional Fields):
{
"docName": "output.pdf",
"docContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPD4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZG9iago1IDAgb2JqCjw8Ci9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihIZWxsbyBXb3JsZCkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1NCAwMDAwMCBuIAowMDAwMDAwMTAxIDAwMDAwIG4gCjAwMDAwMDAxNzAgMDAwMDAgbiAKMDAwMDAwMDI0NCAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjM0MQolJUVPRg==",
"imageFile": "iVBORw0KGgoAAAANSUhEUgAA...",
"imageName": "signature.jpg",
"pages": "1-3",
"alignX": "Right",
"alignY": "Bottom",
"widthInMM": "50",
"heightInMM": "25",
"widthInPx": "142",
"heightInPx": "71",
"marginXInMM": "20",
"marginYInMM": "20",
"marginXInPx": "57",
"marginYInPx": "57",
"opacity": "100",
"showOnlyInPrint": true,
"isBackground": false,
"async": true
}
Code Samples
The PDF4me Sign 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:
PDF Signing Features
Signature Image Control
- Format Support: JPG, PNG, GIF, and other standard image formats
- Quality Preservation: Maintains signature image quality and resolution in PDF output
- Base64 Encoding: Secure signature transmission through Base64 encoding
- Flexible Sizing: Both millimeter and pixel-based sizing options
- Professional Appearance: High-quality signature rendering with clear visibility
Positioning and Layout
- Alignment Control: Precise horizontal and vertical alignment options
- Margin Settings: Both millimeter and pixel-based positioning
- Flexible Placement: Support for any page position and orientation
- Page Targeting: Apply to specific pages or entire documents
- Size Control: Customizable dimensions for optimal placement
Advanced Features
- Opacity Control: Adjustable transparency for subtle or prominent signatures
- Background Mode: Option to place signatures behind or in front of content
- Print Control: Configure signatures to appear only in print or on screen
- Professional Results: Create signatures that enhance document authentication and security
- Flexible Positioning: Control horizontal and vertical alignment with pixel-perfect accuracy
Industry Use Cases & Applications
- Legal & Professional Services
- Finance & Banking
- Business & Enterprise
- Government & Compliance
Legal & Professional Services Use Cases
- Legal Documentation: Apply signatures to legal contracts, agreements, and official documents
- Contract Signing: Sign contracts and agreements digitally for legal validity
- Court Documents: Apply digital signatures to court filings and legal documents
- Compliance Requirements: Meet regulatory requirements for document signing and authentication
Finance & Banking Use Cases
- Invoice Signing: Sign invoices and purchase orders digitally
- Financial Documents: Apply signatures to financial reports and statements
- Loan Documents: Sign loan agreements and financial documents digitally
- Regulatory Compliance: Meet regulatory requirements for financial document signing
Business & Enterprise Use Cases
- Business Workflows: Sign invoices, purchase orders, and business documents digitally
- Document Authentication: Add digital signatures to PDF documents for authentication and verification
- Report Generation: Add signatures to generated reports and official documents
- Corporate Documentation: Sign corporate documents and official communications
Government & Compliance Use Cases
- Compliance Requirements: Meet regulatory requirements for document signing and authentication
- Government Documents: Apply digital signatures to government documents and forms
- Regulatory Documentation: Sign regulatory and compliance documents digitally
- Public Records: Apply signatures to public records and official documents