PDF Signing API

Add signatures to PDF documents with precise positioning and customization options for enhanced document workflow.

Sign PDF API
Add signature images to PDF documents with customizable positioning

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.

Endpoint

POST https://api.mega-pdf.com/api/pdf/sign

Authentication

Authenticate requests using an API key in the x-api-key header.

// Header example
x-api-key: your-api-key

Request Parameters

The API accepts multipart/form-data requests with the following parameters:

ParameterTypeDescriptionRequired
fileFilePDF file to sign (max 50MB)Yes
signatureFileSignature image file (PNG or JPG)Yes
pageStringPage number to add signature (default: 1)No
positionStringPosition on page: center, bl (bottom-left), br (bottom-right), tl (top-left), tr (top-right)No (default: center)
scaleNumberScale factor for signatureNo (default: 0.3)

Example Request

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"

Response Format

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"
}

Code Examples

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));

Supported Signature Formats

The API supports the following signature image formats:

  • PNG (.png) - Recommended for best quality with transparency
  • JPEG/JPG (.jpg, .jpeg) - Good for photos without transparency

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.

Position Options

The position parameter accepts the following values:

ValueDescription
centerCenter of the page
blBottom-left corner
brBottom-right corner
tlTop-left corner
trTop-right corner

The API automatically adds appropriate margins from the edges when using corner positions.