> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://support.pdfgeneratorapi.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# 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](https://docs.pdfgeneratorapi.com/v4/#tag/Services/operation/addWatermark) and [Optimize document](https://docs.pdfgeneratorapi.com/v4/#tag/Services/operation/optimizeDocument) 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](https://docs.pdfgeneratorapi.com/v4/#tag/Services/operation/addWatermark)

###### Request Body Example

```json
{
  "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"
}
```

|| This example includes both image and text watermark configurations. You may choose to use either one or both, depending on your needs.

###### 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) to `1` (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

```json
{
  "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.

![Watermarked PDFs](https://storage.crisp.chat/users/helpdesk/website/-/1/1/e/0/11e0e518fc48ce00/watermarkedpdf_8ow9q9.png)

### 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](https://docs.pdfgeneratorapi.com/v4/#tag/Services/operation/optimizeDocument) endpoint intelligently analyzes and optimizes your PDF while preserving its visual integrity.

You can send your PDF file in two convenient ways:

1.  As a URL to a file already hosted online.
2.  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](https://docs.pdfgeneratorapi.com/v4/#tag/Services/operation/optimizeDocument)

###### Request Body

```json
{
  "file_base64": "JVBERi0xLjcKJeLjz9MKNDggMCBvYmoKPDwvQWNy...",
  "name": "Optimized_PDF",
  "output": "url"
}
```

###### Response

```json
{
    "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

* [How to create a JSON Web Token (JWT)?](/en/article/how-to-create-a-json-web-token-jwt-anv0ot/)
* [How to Integrate with Make](/en/article/how-to-integrate-with-make-18x0r2x/)
* [Roles & Permissions for Master user](/en/article/roles-permissions-for-master-user-1dy7xze/)