Add Text Stamp to PDF - Text Watermark API
PDF4me Add Text Stamp to PDF enables you to add customizable text watermarks to PDF documents for authorization and piracy prevention. This API service processes PDF files and adds text stamps with control over text, position, styling, rotation, and appearance. The API receives PDF content through REST API calls, utilizing Base64 encoding for secure transmission. This solution is ideal for document branding, copyright protection, status indicators, and enterprise PDF 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
- Flexible Positioning: Control horizontal and vertical alignment with pixel-perfect accuracy
- Custom Styling: Choose from various fonts, sizes, colors, and text effects (bold, italic, underline)
- Advanced Formatting: Set opacity, rotation, margins, and background options
- Page Targeting: Apply stamps to specific pages or entire documents
- Print Control: Configure stamps to appear only in print or on screen
- Professional Results: Create watermarks that enhance document security and branding
- 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 text stamp addition operations are performed through a single endpoint:
- Method: POST
- Endpoint:
/api/v2/Stamp
Supported Text Stamping Features
The API provides comprehensive support for various text stamping and watermarking capabilities:
Text Customization Options
- Font Selection: Choose from Arial, Times New Roman, Helvetica, or Courier New
- Size Control: Adjustable font size from 8 to 72
- Color Options: Full color spectrum support with hex color codes (e.g., #FF0000 for red)
- Text Effects: Bold, italic, and underline formatting options
- Custom Text: Support for any text content including symbols and special characters
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 and pixel-based measurements
- Rotation Support: Text rotation: 0 (horizontal), 45 (diagonal), 90 (vertical), -45 (reverse diagonal)
- Flexible Placement: Support for any page position with exact measurements
Advanced Features
- Opacity Control: Adjustable transparency (0-100) for subtle or prominent watermarks
- Background Mode: Option to place text behind or in front of content
- Print Control: Configure stamps to appear in view and print or print only
- Page Targeting: Apply to specific pages or entire documents
- Text Fitting: Automatic text sizing to fit page boundaries (optional)
REST API Parameters
Complete list of parameters for the Add Text Stamp 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 |
|---|---|---|---|
| docName* | String | Output PDF file name with .pdf extension | output.pdf |
| docContent* | Base64 | PDF file content encoded in Base64 | JVBERi... |
| pages* | String | Page options: "all", "1", "1,3,5", "2-5", "1,3,7-10", "2-" | all |
| text* | String | Text to be stamped as watermark | CONFIDENTIAL - PDF4me Watermark |
| alignX* | String | Horizontal alignment: left, center, or right | center |
| alignY* | String | Vertical alignment: top, middle, or bottom | middle |
Optional Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| marginXInMM | String | Horizontal margin from left edge in millimeters | 50 |
| marginYInMM | String | Vertical margin from top edge in millimeters | 50 |
| marginXInPx | String | Horizontal margin from left edge in pixels | 150 |
| marginYInPx | String | Vertical margin from top edge in pixels | 150 |
| opacity | String | Opacity (0-100): 0=invisible, 100=fully opaque | 30 |
| fontName | String | Font name: Arial, Times New Roman, Helvetica, Courier New | Arial |
| fontSize | Integer | Font size (8-72) | 24 |
| fontColor | String | Font color in hex format (e.g., #FF0000 for red) | #FF0000 |
| isBold | Boolean | Make text bold (true) or regular (false) | true |
| isItalics | Boolean | Make text italic (true) or normal (false) | false |
| underline | Boolean | Underline the text (true) or not (false) | false |
| rotate | Integer | Rotation angle: 0 (horizontal), 45 (diagonal), 90 (vertical), -45 (reverse diagonal) | 45 |
| isBackground | Boolean | Place stamp in background (true) or foreground (false) | true |
| showOnlyInPrint | Boolean | Show stamp in view and print (false) or print only (true) | false |
| transverse | Boolean | Transverse positioning (true) or normal (false) | false |
| fitTextOverPage | Boolean | Fit text over entire page (true) or use specified size (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 Add Text Stamp to 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 text stamp 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/Stamp/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,pages,text,alignX,alignY) - Invalid Base64 encoding in
docContent - Invalid alignment values (must be "left", "center", "right" for alignX; "top", "middle", "bottom" for alignY)
- Invalid font size (must be between 8-72)
- 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
- Text stamp 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==",
"pages": "all",
"text": "CONFIDENTIAL - PDF4me Watermark",
"alignX": "center",
"alignY": "middle"
}
Advanced Example (With All Optional Fields):
{
"docName": "output.pdf",
"docContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPD4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZG9iago1IDAgb2JqCjw8Ci9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihIZWxsbyBXb3JsZCkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1NCAwMDAwMCBuIAowMDAwMDAwMTAxIDAwMDAwIG4gCjAwMDAwMDAxNzAgMDAwMDAgbiAKMDAwMDAwMDI0NCAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjM0MQolJUVPRg==",
"pages": "all",
"text": "CONFIDENTIAL - PDF4me Watermark",
"alignX": "center",
"alignY": "middle",
"marginXInMM": "50",
"marginYInMM": "50",
"marginXInPx": "150",
"marginYInPx": "150",
"opacity": "30",
"fontName": "Arial",
"fontSize": 24,
"fontColor": "#FF0000",
"isBold": true,
"isItalics": false,
"underline": false,
"rotate": 45,
"isBackground": true,
"showOnlyInPrint": false,
"transverse": false,
"fitTextOverPage": false,
"async": true
}
Code Samples
The PDF4me Add Text Stamp 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:
Text Stamping Features
Customization Options
- Font Control: Multiple font families with size and color customization
- Text Effects: Bold, italic, and underline formatting options
- Color Management: Full spectrum color support with hex codes
- Text Content: Support for any text including symbols and special characters
- Professional Styling: High-quality text rendering with clear visibility
Positioning and Layout
- Alignment Control: Precise horizontal and vertical alignment options
- Margin Settings: Both millimeter and pixel-based positioning
- Rotation Support: Text rotation for diagonal or angled watermarks
- Flexible Placement: Support for any page position and orientation
- Page Targeting: Apply to specific pages or entire documents
Advanced Features
- Opacity Control: Adjustable transparency for subtle or prominent watermarks
- Background Mode: Option to place text behind or in front of content
- Print Control: Configure stamps to appear only in print or on screen
- Text Fitting: Automatic text sizing to fit page boundaries
- Transverse Mode: Apply stamps across the entire page
Industry Use Cases & Applications
- Legal & Professional Services
- Business & Enterprise
- Finance & Banking
- Government & Compliance
Legal & Professional Services Use Cases
- Legal Documentation: Apply legal disclaimers and confidentiality notices to legal documents
- Contract Stamping: Add status stamps to contracts and agreements
- Confidentiality Notices: Apply confidentiality stamps to sensitive legal documents
- Compliance Stamps: Add regulatory compliance notices to legal documents
Business & Enterprise Use Cases
- Document Branding: Add company logos, watermarks, and branding elements to PDF documents
- Status Indicators: Add "DRAFT", "CONFIDENTIAL", or "APPROVED" stamps to indicate document status
- Report Generation: Add timestamps, page numbers, and report identifiers to generated documents
- Corporate Branding: Apply consistent branding across business documents
Finance & Banking Use Cases
- Financial Reports: Add status stamps to financial reports and statements
- Invoice Stamping: Apply approval stamps to invoices and purchase orders
- Compliance Documentation: Add regulatory stamps to financial documents
- Audit Trails: Create audit trails with timestamp stamps on financial documents
Government & Compliance Use Cases
- Copyright Protection: Apply copyright notices and ownership stamps to protect intellectual property
- Regulatory Compliance: Add compliance stamps to meet regulatory requirements
- Official Documentation: Apply official stamps to government documents
- Public Records: Add classification stamps to public records and documents