How to Watermark PDFs using text

Learn how to add text watermarks to PDFs using a simple API-based approach.

Overview

In this guide, we’ll start with a basic text watermark using a standard PDF font and then show how to apply a custom font. You can follow along step by step or jump straight to the example you need.

Prerequisites

Before you start, make sure you have:

  • A PDF file you want to watermark.
  • A PDFGate API key (you can get one for free from the dashboard).

Basic watermark with standard PDF font

On this example, we will use the following parameters of the Watermark PDF API endpoint:

  • file: The bytes of the PDF file you want to watermark. Alternatively, if you have already generated a file using our HTML to PDF API, you can use the documentId parameter and send the ID instead of the file bytes.
  • type: Here we will define the type of the watermark. We will set the value to text on this example.
  • text: This parameter sets the text that will appear as the watermark. On this example, we will set it to WATERMARKED.
  • rotate: Rotates the watermark text. In this example, the text is rotated by 30 degrees.
  • font: This parameter accepts one of the standard PDF fonts (view all supported fonts in the Watermark API docs). On this example, we will use the helvetica-boldoblique font.
  • fontSize: For this example, we will set the font size to 20 points.
  • fontColor: This parameter can accept standard HEX (#eb4034) or RGB (rgb(235, 64, 52)) colors. This example uses the color #eb4034.
  • opacity: On this example, we will set the opacity of the watermark to 0.2.
CURL
NODE.JS
PYTHON
GO
PHP
JAVA
RUBY
copy-integration-source-code-icon
curl -X POST "https://api.pdfgate.com/watermark/pdf" \ -H "Authorization: Bearer YOUR_API_KEY" \ -F "file=@YOUR_FILE.pdf" \ -F "type=text" \ -F 'text=WATERMARKED' \ -F 'font=helvetica-boldoblique' \ -F 'fontColor=#eb4034' \ -F "rotate=30" \ -F "opacity=0.2" \ --output watermarked.pdf

Watermark with custom font

To create a watermark with a custom font, you need a .ttf or.otf font file. If you don't have one, you can download it from a font library website.

  • file: The PDF file in bytes to watermark.
  • type: We will set it to text, as in the example above.
  • text: We will set the value to WATERMARKED.
  • rotate: Set it to 30 degrees.
  • fontFile: This parameter accepts the custom font file in bytes.
  • fontSize: Set it to 20 points.
  • fontColor: This example uses the color #eb4034.
  • opacity: Set it to 0.2.
CURL
NODE.JS
copy-integration-source-code-icon
curl -X POST "https://api.pdfgate.com/watermark/pdf" \ -H "Authorization: Bearer YOUR_API_KEY" \ -F "file=@YOUR_FILE.pdf" \ -F "fontFile=@YOUR_FONT_FILE.ttf" \ -F "type=text" \ -F 'text=WATERMARKED' \ -F 'fontColor=#eb4034' \ -F "rotate=30" \ -F "opacity=0.2" \ --output watermarked.pdf

Watermark position

By default, the API positions the watermark in the center of each page. However, if you have specific requirements and want to place it at specific coordinates, you can use the following parameters:

  • xPosition: Sets the horizontal position in points.
  • yPosition: Sets the vertical position in points.

Related guides

If you need to apply a logo or image instead of text, see our Image Watermarking guide.