Automate PDF Watermarking: Add Logos to Documents in Bulk
You have 100 contracts that need a "CONFIDENTIAL" stamp. Or 500 invoices that need your company logo. Opening each PDF in Acrobat and manually adding a watermark is not an option.
In this tutorial, we will use Ruby and the aPDF.io Overlay API to automatically stamp a watermark onto multiple PDFs. One script, hundreds of branded documents.
The Quick Solution
require 'rest-client'
require 'json'
response = RestClient.post(
'https://apdf.io/api/pdf/page/overlay',
{
file: 'https://your-server.com/contract.pdf',
overlay: 'https://your-server.com/confidential-watermark.pdf',
repeat: '1'
},
{
Authorization: 'Bearer YOUR_API_TOKEN',
Accept: 'application/json',
content_type: 'application/json'
}
)
result = JSON.parse(response.body)
puts result['file'] # URL to the watermarked PDF
That is it. Your contract now has the watermark applied to every page.
How It Works
The "overlay" operation takes two PDFs and layers one on top of the other:
file- Your original document (the contract)overlay- The watermark PDF (semi-transparent "CONFIDENTIAL" text or your logo)repeat- Repeat the "overlay" operation with page 1 from the watermark PDF on all pages
The API merges them, placing the overlay on top of each page. If your watermark has transparency, the original content shows through perfectly.
Step 1: Create Your Watermark PDF
Your watermark needs to be a PDF file. Here are two common approaches:
Option A: Use a Design Tool
Create a single-page PDF in Canva, Figma, or Adobe Illustrator. Add your "CONFIDENTIAL" text
or logo with 20-30% opacity. Export as PDF.
Option B: Use HTML
You can use the aPDF.io Create endpoint
to generate a watermark PDF from HTML. This gives you full control over positioning and transparency.
<div style="
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(-45deg);
font-size: 80px;
color: rgba(255, 0, 0, 0.15);
font-weight: bold;
">
CONFIDENTIAL
</div>
Step 2: Get Your API Token
- Sign up at aPDF.io (it's free).
- Copy your API Token from the dashboard.
Step 3: Bulk Watermarking Script
Here is a complete Ruby script that processes multiple contracts and adds a watermark to each one:
require 'rest-client'
require 'json'
API_TOKEN = 'YOUR_API_TOKEN_HERE'
API_URL = 'https://apdf.io/api/pdf/page/overlay'
# The watermark PDF (semi-transparent "CONFIDENTIAL" stamp)
WATERMARK_URL = 'https://your-server.com/confidential-watermark.pdf'
# List of contracts to watermark
contracts = [
'https://your-server.com/contracts/contract-001.pdf',
'https://your-server.com/contracts/contract-002.pdf',
'https://your-server.com/contracts/contract-003.pdf'
]
puts "Starting bulk watermarking...\n"
contracts.each_with_index do |contract_url, index|
begin
puts "Processing contract #{index + 1}/#{contracts.length}..."
response = RestClient.post(
API_URL,
{
file: contract_url,
overlay: WATERMARK_URL,
repeat: '1'
},
{
Authorization: "Bearer #{API_TOKEN}",
Accept: 'application/json',
content_type: 'application/json'
}
)
result = JSON.parse(response.body)
puts " Done: #{result['file']}"
rescue RestClient::ExceptionWithResponse => e
puts " Error: #{e.response}"
rescue => e
puts " Error: #{e.message}"
end
end
puts "\nBulk watermarking complete!"
Run the script
gem install rest-client
ruby watermark_contracts.rb
Output
Starting bulk watermarking...
Processing contract 1/3...
Done: https://apdf-files.s3.eu-central-1.amazonaws.com/a1b2c3d4.pdf
Processing contract 2/3...
Done: https://apdf-files.s3.eu-central-1.amazonaws.com/e5f6g7h8.pdf
Processing contract 3/3...
Done: https://apdf-files.s3.eu-central-1.amazonaws.com/i9j0k1l2.pdf
Bulk watermarking complete!
Each URL is a watermarked version of the original contract. You can download them or send them directly to recipients. Note: These URLs are valid for 1 hour.
Advanced: Control Which Pages Get Watermarked
Sometimes you only want the watermark on specific pages. The API provides two parameters for this:
from- Which pages from the watermark PDF to useto- Which pages in your document should receive the watermark
For example, to watermark only pages 2 through 5 of your contract:
response = RestClient.post(
API_URL,
{
file: contract_url,
overlay: WATERMARK_URL,
to: '2-5', # Only watermark pages 2, 3, 4, and 5
repeat: '1'
},
{
Authorization: "Bearer #{API_TOKEN}",
Accept: 'application/json',
content_type: 'application/json'
}
)
Use to: '2-z' to watermark from page 2 to the end (useful for skipping cover pages).
Use Case: Adding Company Logos
The same technique works for adding company logos to documents. Create a PDF with your logo positioned in the corner (with transparency), then overlay it onto your documents.
This is commonly used for:
- Branding white-label reports with your company logo
- Adding "DRAFT" stamps to preliminary documents
- Stamping "APPROVED" or "REVIEWED" on processed files
- Adding page numbers or headers to existing PDFs
Conclusion
Watermarking PDFs manually is tedious. With the aPDF.io Overlay API, you can process hundreds of documents in seconds. The watermark stays consistent, and your Ruby script can be scheduled to run automatically whenever new documents arrive.
Next Steps
- Protect the Documents: Use the Password Protection endpoint to prevent recipients from editing the watermarked files.
- Merge Multiple Documents: Combine watermarked contracts with cover letters using the Merge endpoint.