Add signatures to PDF documents with precise positioning and customization options for enhanced document workflow.
The Sign PDF API allows you to add signature images to PDF documents. You can specify the page, position, and scale of the signature for professional document finalization. This is ideal for adding signatures to contracts, agreements, and other business documents.
POST https://api.mega-pdf.com/api/pdf/sign
Authenticate requests using an API key in the x-api-key
header.
// Header example
x-api-key: your-api-key
The API accepts multipart/form-data
requests with the following parameters:
Parameter | Type | Description | Required |
---|---|---|---|
file | File | PDF file to sign (max 50MB) | Yes |
signature | File | Signature image file (PNG or JPG) | Yes |
page | String | Page number to add signature (default: 1) | No |
position | String | Position on page: center, bl (bottom-left), br (bottom-right), tl (top-left), tr (top-right) | No (default: center) |
scale | Number | Scale factor for signature | No (default: 0.3) |
Add a signature to a PDF using cURL:
curl -X POST https://api.mega-pdf.com/api/pdf/sign \
-H "x-api-key: your-api-key" \
-F "file=@/path/to/document.pdf" \
-F "signature=@/path/to/signature.png" \
-F "page=1" \
-F "position=br" \
-F "scale=0.4"
Successful responses include the signed PDF file URL:
{
"success": true,
"message": "PDF signed successfully",
"fileUrl": "/api/file?folder=signatures&filename=uuid-signed.pdf",
"filename": "uuid-signed.pdf",
"originalName": "document.pdf"
}
Error responses:
{
"success": false,
"error": "Signature must be PNG or JPG image"
}
Using the Sign PDF API with JavaScript:
const formData = new FormData();
formData.append('file', fs.createReadStream('document.pdf'));
formData.append('signature', fs.createReadStream('signature.png'));
formData.append('page', '2'); // Sign page 2
formData.append('position', 'br'); // Bottom right
formData.append('scale', '0.35');
fetch('https://api.mega-pdf.com/api/pdf/sign', {
method: 'POST',
headers: {
'x-api-key': 'your-api-key'
},
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
console.log('PDF signed successfully:', data.fileUrl);
} else {
console.error('Failed to sign PDF:', data.error);
}
})
.catch(error => console.error('Error:', error));
The API supports the following signature image formats:
For best results, use a transparent PNG with a clean background for your signature. This ensures the signature appears naturally on the document without covering important content with a white background.
The position
parameter accepts the following values:
Value | Description |
---|---|
center | Center of the page |
bl | Bottom-left corner |
br | Bottom-right corner |
tl | Top-left corner |
tr | Top-right corner |
The API automatically adds appropriate margins from the edges when using corner positions.