Polish Your PDFs – Add Watermarks & Optimize
Adding watermarks and optimizing PDFs are crucial final steps when preparing documents for sharing, branding, or secure distribution. Our API’s Add watermark and Optimize document endpoints allow you to enhance your PDFs by overlaying custom watermarks and then compressing the file size for faster loading and efficient storage.
In this tutorial, we’ll walk you through the process of adding a watermark to your PDF and then optimizing the file to produce a polished, lightweight document ready for any use case.
1. Add watermark
Whether your PDF is stored online or encoded as base64, you can add a watermark to highlight branding or protect your document. The watermark can be a text overlay or an image.
Endpoint Details
- HTTP Method:
POST
- Request URL:
https://us1.pdfgeneratorapi.com/api/v4/pdfservices/watermark
- Documentation: Official API Docs
Request Body Example
{
"file_url": "https://us1.pdfgeneratorapi.com/api/v4/documents/66/b0030f5646...",
"watermark": {
"image": {
"content_url": "https://pdfa.org/wp-content/uploads/2021/01/Logo-AR-FINAL-BLUE-wpv_300x.png",
"position": "center",
"rotation": 45,
"scale": 1
},
"text": {
"content": "Confidential",
"color": "#000000",
"size": 72,
"opacity": 0.5,
"position": "center",
"rotation": 45
}
},
"output": "url",
"name": "Watermarked_PDF"
}
Field description
Image-specific fields
- content_url – URL of the image to be used as a watermark.
- scale – size of the image, where
1
= original size,0.5
= half size, etc.
Text-specific fields
- content – the text string to be displayed as a watermark.
- color – HEX color code of the text (e.g.,
#000000
= black). - size – font size in points (e.g.,
72
). - opacity – transparency of the watermark, from
0
(invisible) to1
(fully opaque).
Shared fields (apply to both image and text)
- position – placement of the watermark (
top-left
,top-right
,center
,bottom-left
,bottom-right
). - rotation – rotation angle in degrees (e.g.,
0
= no rotation,45
= diagonal).
Response Example
{
"response": "JVBERi0xLjcKJeLjz9MKNDggMCBvYmoKPDwvQWNy...",
"meta": {
"name": "Watermarked_PDF.pdf",
"display_name": "Watermarked_PDF",
"encoding": "base64",
"content-type": "application/pdf"
}
}
Below is an example showing both watermark types applied separately — image watermark on the left, text watermark on the right.
2. Optimize document
Once your PDF is finalized and ready, the next step is to reduce its file size to speed up downloads, save storage space, and improve user experience. Our Optimize document endpoint intelligently analyzes and optimizes your PDF while preserving its visual integrity.
You can send your PDF file in two convenient ways:
- As a URL to a file already hosted online.
- As a base64 encoded string, ideal for direct integration within your application's logic.
Endpoint Details
- HTTP Method:
POST
- Request URL:
https://us1.pdfgeneratorapi.com/api/v4/pdfservices/optimize
- Documentation: Official API Docs
Request Body
{
"file_base64": "JVBERi0xLjcKJeLjz9MKNDggMCBvYmoKPDwvQWNy...",
"name": "Optimized_PDF",
"output": "url"
}
Response
{
"response": "https://us1.pdfgeneratorapi.com/api/v4/documents/66/efa74021c1...",
"meta": {
"name": "Optimized_PDF.pdf",
"display_name": "Optimized_PDF",
"encoding": "binary",
"content-type": "application/pdf",
"public_id": "efa74021c1162e9f1afb4f5f8692ea40",
"stats": {
"original_size": 2000,
"optimized_size": 800
}
}
}
The stats
field in the response provides valuable metadata, showing the original size and the optimized size, so you can immediately see the impact of the optimization.
cURL Example
For a quick test or direct integration, you can use the following cURL
command:
curl --request POST \
--url https://us1.pdfgeneratorapi.com/api/v4/pdfservices/optimize \
--header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
--header 'content-type: application/json' \
--data '{"file_url":"YOUR_PDF_FILE_URL_OR_BASE64","output":"base64"}'
Related articles you may find helpful
Updated on: 10/09/2025
Thank you!