Prompt

How do I watermark PDFs programmatically?

Technology / Developer Tools1 observationLast seen Oct 12, 2026

Latest observation

Oct 12, 2026OpenAI APIWeb search: off

There are a few common ways to watermark PDFs programmatically, depending on your language and whether you want to add text, an image, or both.

Common approaches

1) Use a PDF library

Best if you want full control and reliable results.

Popular libraries:

  • Python: pypdf, reportlab
  • JavaScript/Node.js: pdf-lib
  • Java: Apache PDFBox
  • C#: iText, PdfSharp, IronPDF
  • Go: gofpdf, unipdf

2) Stamp an existing watermark onto each page

Typical flow:

  1. Create a transparent watermark page/image.
  2. Overlay it onto every page of the target PDF.
  3. Save the result.

3) Generate the PDF with the watermark already included

If you’re creating PDFs yourself, draw the watermark as part of the page rendering.


Example in Python using pypdf + reportlab

This is a common pattern for adding a text watermark:

from pypdf import PdfReader, PdfWriter
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from io import BytesIO

def create_watermark(text, page_size):
    packet = BytesIO()
    can = canvas.Canvas(packet, pagesize=page_size)
    can.setFillAlpha(0.2)  # transparency
    can.setFont("Helvetica-Bold", 40)
    can.saveState()
    can.translate(page_size[0] / 2, page_size[1] / 2)
    can.rotate(45)
    can.drawCentredString(0, 0, text)
    can.restoreState()
    can.save()
    packet.seek(0)
    return PdfReader(packet).pages[0]

input_pdf = PdfReader("input.pdf")
output_pdf = PdfWriter()

for page in input_pdf.pages:
    watermark = create_watermark("CONFIDENTIAL", (float(page.mediabox.width), float(page.mediabox.height)))
    page.merge_page(watermark)
    output_pdf.add_page(page)

with open("watermarked.pdf", "wb") as f:
    output_pdf.write(f)

Example in Node.js using pdf-lib

const fs = require('fs');
const { PDFDocument, rgb, degrees } = require('pdf-lib');

async function addWatermark() {
  const pdfBytes = fs.readFileSync('input.pdf');
  const pdfDoc = await PDFDocument.load(pdfBytes);
  const pages = pdfDoc.getPages();

  for (const page of pages) {
    const { width, height } = page.getSize();
    page.drawText('CONFIDENTIAL', {
      x: width / 2 - 100,
      y: height / 2,
      size: 40,
      rotate: degrees(45),
      color: rgb(0.7, 0.7, 0.7),
      opacity: 0.2,
    });
  }

  const outBytes = await pdfDoc.save();
  fs.writeFileSync('watermarked.pdf', outBytes);
}

addWatermark();

If you want an image watermark

Use the same process, but draw an image instead of text.

Python libraries:

  • reportlab for creating the watermark overlay
  • pypdf for merging

Node.js:

  • pdf-lib can embed and draw images directly.

Important considerations

  • Transparency: Use alpha/opacity so the watermark doesn’t obscure content.
  • Page size/orientation: Handle portrait and landscape pages correctly.
  • Performance: For large PDFs, avoid excessive page rendering unless needed.
  • Compliance/security: A watermark is not a security feature by itself; it’s mostly deterrence/identification.

If you need stronger protection

Consider:

  • password protection / permissions
  • digital signatures
  • rights management / DRM
  • server-side access control

If you tell me your preferred language (Python, Node, Java, C#, etc.), I can give you a ready-to-run example.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.