Add a text watermark to a PDF

Use this action to personalize a PDF document with a text watermark.

Endpoints

POST https://api.pdfblocks.com/v1/add_watermark/text

Global endpoint (default)

POST https://eu.api.pdfblocks.com/v1/add_watermark/text

European-only endpoint

Parameters

The endpoint accepts multipart/form-data request bodies with the folowing parameters:

file Required

The content of the input PDF document

line_1 Required

The first line of text of the watermark

  • The maximum length is 32 characters

line_2 optional

The second line of text of the watermark

  • The maximum length is 32 characters.

line_3 optional

The third line of text of the watermark

  • The maximum length is 32 characters

template optional

An integer with the id of the text watermark template

color optional

The color of the text watermark

  • Valid values are Red, Blue, Gray, and Black
  • The default value is Gray

transparency optional

An integer with the transparency level for the text watermark from 0 (opaque) to 100 (transparent)

  • Integer value between 0 and 100
  • The default value is 75

margin optional

A decimal value with the distance in inches from the border of the page to the text watermark.

  • Decimal value greater than 0.0
  • The default value is 1.0

Returns

If successful, the call returns a response with Content-Type: application/pdf with the content of the watermarked PDF document. Otherwise, this call returns an error.

Code examples

curl

curl \
-F file=@input.pdf \
-F line_1='Jane Doe' \
-F line_2='ACME, Inc' \
-F line_3='Confidential' \
-F template=1001 \
-F color=Gray \
-F transparency=75 \
-F margin=1.0 \
-o watermarked.pdf \
-H 'X-Api-Key: your_api_key' \
https://api.pdfblocks.com/v1/add_watermark/text

Python

# pip install requests

import requests

url = 'https://api.pdfblocks.com/v1/add_watermark/text'

body = {
  'file' : open('input.pdf', 'rb'),
  'line_1' : 'Jane Doe',
  'line_2' : 'ACME, Inc',
  'line_3' : 'Confidential',
  # 'template' : 1001,
  # 'color' : 'Gray',
  # 'transparency' : 75,
  # 'margin' : 1.0,
}

headers = { 'X-Api-Key' : 'your_api_key' }

response = requests.post(url, files=body, headers=headers)

if response.status_code == 200:
  with open('watermarked.pdf', 'wb') as output:
    for chunk in response.iter_content():
        output.write(chunk)

Ruby

# gem install http

require 'http'

url = 'https://api.pdfblocks.com/v1/add_watermark/text'

body = {
  file: HTTP::FormData::File.new('input.pdf'),
  line_1: 'Jane Doe',
  line_2: 'ACME, Inc',
  line_3: 'Confidential',
  # template: 1001,
  # color: 'Gray',
  # transparency: 75,
  # margin: 1.0,
}

headers = { 'X-Api-Key' => 'your_api_key' }

response = HTTP.post(url, form: body, headers: headers)

if response.status.ok?
  File.open('watermarked.pdf', 'wb') do |output|
    response.body.each { |chunk| output.write(chunk) }
  end
end

C# (.NET Core)

// Using .NET Core 3.1

using System.IO;
using System.Net.Http;

class Program
{
    static void Main()
    {
        string url = "https://api.pdfblocks.com/v1/add_watermark/text";

        var inputFile = new FileStream("input.pdf", FileMode.Open, FileAccess.Read);

        var body = new MultipartFormDataContent();
        body.Add(new StreamContent(inputFile), "file");
        body.Add(new StringContent("Jane Doe"), "line_1");
        body.Add(new StringContent("ACME, Inc"), "line_2");
        body.Add(new StringContent("Confidential"), "line_3");
        // body.Add(new StringContent("1001"), "template");
        // body.Add(new StringContent("Gray"), "color");
        // body.Add(new StringContent("75"), "transparency");
        // body.Add(new StringContent("1.0"), "margin");

        var message = new HttpRequestMessage(HttpMethod.Post, url);
        message.Content = body;
        message.Headers.Add("X-Api-Key", "your_api_key");

        var client = new HttpClient();
        var response = client.SendAsync(message).Result;
        if(response.IsSuccessStatusCode)
        {
            using var output = new FileStream("watermarked.pdf", FileMode.Create, FileAccess.Write);
            response.Content.CopyToAsync(output).Wait();
        }
    }
}