Concept · Stamping
Add Watermarks to
PDF Files in Code
A watermark is text or an image stamped across every page as a visible
overlay. Common for status labels like DRAFT or
CONFIDENTIAL, copy attribution, and light branding. rust-pdf
applies watermarks to existing documents via EditableDoc,
with full control over text, size, color, opacity, and rotation.
The simplest analogy: a rubber stamp pressed diagonally across the page
Before digital documents, an office worker would take a large rubber stamp, ink it red, and press it across an invoice or contract at an angle. Anyone reading the document could see at once that it was a draft, a copy, or had been voided. The stamp did not change the words underneath; it sat on top as a clear, visible signal.
A PDF watermark does exactly the same thing in code. The underlying page content stays as it is. A semi-transparent text overlay, or a faint logo, is painted on top of every page so it is impossible to miss when reading, viewing, or printing. The classic choice is a diagonal stamp at 45 degrees, large enough to span the page but transparent enough that the content beneath stays legible.
Text vs image watermarks
rust-pdf supports two forms. Both are applied to an existing PDF via
EditableDoc, and both are written into the page content
stream so they appear in any viewer and when printed.
Text watermark
A string stamped across every page at a chosen size, RGB color, opacity, and rotation. The typical use is a status label such as CONFIDENTIAL, DRAFT, or COPY, rendered diagonally at 45 degrees with an opacity of 0.15 to 0.25.
Image watermark
A logo or other image file stamped across every page at a given width, height, and opacity. Use this for light branding on preview or sample documents, or to tag issued copies with a customer logo.
The options you control
Every parameter has a sensible default, but you can tune each one independently to match your document style or branding guidelines.
Text
The string to stamp. Typically one short word or phrase such as CONFIDENTIAL, DRAFT, COPY, or SAMPLE.
Size
Font size in points. A size of 48 to 72 spans a letter-sized page well for a diagonal stamp. Smaller values suit narrow banners or footers.
Color
RGB as three floats from 0 to 1. A deep red such as (0.7, 0.1, 0.1) is the traditional stamp color. Grey works for neutral branding.
Opacity
A float from 0 (invisible) to 1 (fully opaque). 0.15 to 0.25 keeps the content readable while the stamp is clearly visible.
Rotation
Angle in degrees counter-clockwise. 45 is the classic diagonal. Use 0 for a horizontal banner at the top or bottom of the page.
Visible mark, not access control
A watermark is applied to the page content, so it shows in any viewer and prints. It is the right tool for attribution and deterrence, not for locking a document down.
A visible watermark deters casual misuse. Anyone who receives the document can see immediately that it is confidential, a draft, or a numbered copy. That social signal is often enough, and it survives printing and screenshots.
It is not, however, encryption. A determined party can remove or
obscure an overlay because the underlying page content is still
present. If you need to restrict who can open, print, or copy a
document, use AES-256 encryption from
EditableDoc.encrypt alongside the watermark. The two
complement each other: the watermark signals, the encryption enforces.
When to use a watermark
Watermarks are a lightweight, universally understood signal. They work wherever you need a visible mark without changing the document's underlying structure.
Confidential documents
Contracts, financial reports, and legal drafts marked CONFIDENTIAL so every recipient is aware of the handling requirement before they read the first line.
Draft documents
Proposals and reports in review marked DRAFT so readers know the content is not yet final and should not be actioned or forwarded as authoritative.
Numbered issued copies
Generating one PDF per recipient with a unique copy number stamped on each page, so the source of any leaked copy can be traced back to its recipient.
Light branding
A faint company logo or domain name stamped at low opacity across white-label reports or data exports, keeping authorship visible without obscuring content.
Sample and preview files
Sending a preview of a paid document or template with SAMPLE or PREVIEW stamped across every page, making clear that the full version requires a purchase or license.
Audit and compliance
Marking archived or distributed copies with a timestamp or approval status so compliance teams can identify which version was in circulation at a given time.
How to add a watermark to a PDF with rust-pdf
Load a PDF and stamp diagonal text (or an image) across every page.
# pip install rustpdf
import rustpdf
ed = rustpdf.EditableDoc.load(open("report.pdf", "rb").read())
ed.watermark_text("CONFIDENTIAL", size=64, color=(0.7, 0.1, 0.1),
opacity=0.20, rotation_deg=45)
ed.save("report_watermarked.pdf")
# Or stamp a logo image instead:
# ed.watermark_image_file("logo.png", width=240, height=80, opacity=0.15)
// dotnet add package RustPdf
using RustPdf;
using var ed = EditableDoc.Load(File.ReadAllBytes("report.pdf"));
ed.WatermarkText("CONFIDENTIAL", size: 64, color: (0.7, 0.1, 0.1),
opacity: 0.20, rotationDeg: 45);
ed.Save("report_watermarked.pdf");
// go get github.com/rustpdf/rustpdf-go@latest
ed, _ := rustpdf.Load(mustRead("report.pdf"))
defer ed.Close()
ed.WatermarkText("CONFIDENTIAL", 64, 0.7, 0.1, 0.1, 0.20, 45) // text,size,r,g,b,opacity,rotationDeg
ed.Save("report_watermarked.pdf")
// npm install rustpdf
const { EditableDoc } = require("rustpdf");
const fs = require("fs");
const ed = EditableDoc.load(fs.readFileSync("report.pdf"));
ed.watermarkText("CONFIDENTIAL", { size: 64, color: [0.7, 0.1, 0.1], opacity: 0.20, rotationDeg: 45 });
ed.save("report_watermarked.pdf");
The same API is available in Python, C#/.NET, Go, Node.js, Java, PHP, Ruby, Delphi, and Swift. One Rust core, nine languages. See the documentation for the full reference.
Watermark FAQ
How do I add a watermark to a PDF in code?
Load the existing PDF into an EditableDoc and call watermark_text with the text, size, color, opacity and rotation you want. rust-pdf stamps the overlay onto every page and you save the result. The call is one line in Python, C#, Go, Node, Java, PHP, Ruby, Delphi or Swift.
Can I use an image as a watermark?
Yes. Use watermark_image_file (or WatermarkImageFile in C# and Go) and pass the path to your image file along with the target width, height and opacity. This is useful for stamping a faint logo or brand mark across every page.
What options can I set (opacity, rotation, color)?
For a text watermark you can set the text string, font size, RGB color as three floats between 0 and 1, opacity as a float between 0 and 1, and rotation in degrees. The classic diagonal stamp uses 45 degrees and an opacity of around 0.15 to 0.25 so the underlying content stays readable. For an image watermark you set width, height and opacity.
Does the watermark appear when printing?
Yes. The watermark is applied directly to the page content stream, so it is part of the PDF itself. It appears on screen in any viewer and is included when the document is printed, just like any other content on the page.
Is a watermark a form of protection?
A visible watermark deters casual misuse and makes copied documents attributable, but it is not access control. A determined party can remove or obscure a visible overlay. If you need to restrict who can open, copy or print a document, pair the watermark with encryption using encrypt_with AES-256. The two work well together: the watermark deters, the encryption enforces.
Stamp watermarks across PDFs in your language
One Rust core, nine language bindings. Prototype for free, license the corporate features when you ship.