PDF Watermark API

PSPDFKit API is an HTTP API that lets you add watermarks to your documents. Use the PDF Watermark API to add text or image watermarks to PDFs via a single API call.

Try It Out

This example will watermark all the pages of your document with the supplied logo.

1

Use Your Free Credits

Sign up to get 100 free credits, or log in to automatically add your API key to sample code.

Add a File

Add a PDF named document.pdf and an image file named logo.png to your project folder. You can also use our sample PDF and our sample image.

Run a Command

Copy the curl command and run it in that same folder via the terminal or your editor’s terminal.

View the Results

Open result.pdf in your project folder to view the results.

Shell
    curl -X POST https://api.pspdfkit.com/build \
        -H "Authorization: Bearer your_api_key_here" \
        -o result.pdf \
        -F document=@document.pdf \
        -F logo=@logo.png \
        -F instructions='{
            "parts": [
              { "file": "document" }
            ],
            "actions": [{
              "type": "watermark",
              "image": "logo",
              "width": "25%"
            }]
          }'
Using Postman? Download our official collection and start using the API with a single click. Read more 

Your API Key

Get access to your API key when you create an account. Once your account has been created, you’ll receive 100 free credits for using with any of our API tools.

Your API key has automatically been inserted into the API example code. Run the sample code in your terminal to execute the API call.

Already Have an Account? Sign In →

Examples

The following sections show more examples of how the watermark API can be used.

Multiple Watermarks

This example will add multiple watermarks to the document. The image watermark will be placed in the center of the screen, while the text will be positioned in the bottom left corner:

Shell
    curl -X POST https://api.pspdfkit.com/build \
        -H "Authorization: Bearer your_api_key_here" \
        -o result.pdf \
        -F document=@Example.pdf \
        -F company-logo=@logo.png \
        -F instructions='{
            "parts": [{
              "file": "document"
            }],
            "actions": [{
              "type": "watermark",
              "image": "company-logo",
              "width": "50%"
            },
            {
              "type": "watermark",
              "text": "Property of PSPDFKit",
              "width": 150,
              "height": 20,
              "left": 0,
              "bottom": "100%"
            }]
          }'

Aligning Watermarks

This example will show some common watermark alignments by adding a text watermark in each of the corners:

Shell
    curl -X POST https://api.pspdfkit.com/build \
        -H "Authorization: Bearer your_api_key_here" \
        -o result.pdf \
        -F document=@Example.pdf \
        -F instructions='{
            "parts": [{
              "file": "document"
            }],
            "actions": [{
              "type": "watermark",
              "text": "Top Left",
              "width": 150,
              "height": 20,
              "left": 0,
              "top": 0
            },
            {
              "type": "watermark",
              "text": "Top Center",
              "width": 150,
              "height": 20,
              "top": 0
            },
            {
              "type": "watermark",
              "text": "Top Right",
              "width": 150,
              "height": 20,
              "right": "100%",
              "top": 0
            },
            {
              "type": "watermark",
              "text": "Center Left",
              "width": 150,
              "height": 20,
              "left": 0
            },
            {
              "type": "watermark",
              "text": "Center",
              "width": 150,
              "height": 20
            },
            {
              "type": "watermark",
              "text": "Center Right",
              "width": 150,
              "height": 20,
              "right": "100%"
            },
            {
              "type": "watermark",
              "text": "Bottom Left",
              "width": 150,
              "height": 20,
              "left": 0,
              "bottom": "100%"
            },
            {
              "type": "watermark",
              "text": "Bottom Center",
              "width": 150,
              "height": 20,
              "bottom": "100%"
            },
            {
              "type": "watermark",
              "text": "Bottom Right",
              "width": 150,
              "height": 20,
              "right": "100%",
              "bottom": "100%"
            }]
          }'

Reference

The following schema shows all the options and valid inputs for the watermark action:

JavaScript
    // The size of the watermark can either be a positive integer or a percentage (e.g. representing a ratio of the page dimension).
    type Dimension = number | string;
    
    // The position of the watermark can either be a non-negative integer or a percentage (e.g. representing a ratio of the page dimension).
    type Position = number | string;
    
    // Represents one part that was sent in the multipart request. Should be the
    // `name` that was specified for the part.
    type MultipartReference = string;
    
    type WatermarkAction = {
      type: "watermark",
    
      // Only either "text" or "image" can be specified.
      text?: string, // When specified, this is the text that the watermark will contain.
      image?: MultipartReference, // When specified, this is the image that will be used as the watermark.
    
      // For images, one dimension needs to be specified. For text watermarks, both dimensions need to be specified.
      width?: Dimension,
      height?: Dimension,
    
      // The position defaults to the center of the page.
      // You can only specify one position per axis, so either:
      // top or bottom
      // and either
      // left or right.
      top?: Position,
      right?: Position,
      bottom?: Position,
      left?: Position,
    };