How to use it
- Drop the PDF onto the box. The first page appears in the preview as soon as it has been rendered.
- Choose “Text” and type the words (e.g. CONFIDENTIAL, DRAFT, a name or a date), or “Image or logo” and drop a PNG with transparency.
- Adjust size (or logo width), colour, opacity, rotation and position while watching the preview. Limit the pages if only some should carry the mark.
- Press “Add watermark” and download. The original file is not modified.
Example
“DRAFT” in Helvetica Bold at 96 pt, 30% grey, rotated 45° and centred on an A4 page: the text is about 325 pt wide and 69 pt high (cap height 0.718 × 96), so its rotated bounding box is 279 × 279 pt and its centre sits at (297.6, 420.9) pt – the middle of the page. A 400 × 100 px logo at 35% width on the same page is drawn 208 × 52 pt in the bottom-right corner, 24 pt from the edges.
How the watermark is placed
pdf-lib opens the file and, for each selected page, appends a drawText or drawImageoperation with the chosen opacity (an ExtGState with constant alpha) and rotation. pdf-lib rotates around the object’s own origin (bottom-left corner), so the tool first computes the bounding box of the rotated watermark, anchors that box at the chosen position with a 24 pt margin, and converts the box centre back into an origin:
origin = centre + R(θ) · (−w/2, −h/2)For text, w is the string width from the font’s metrics and h the cap height (0.718 × size for Helvetica, 0.676 for Times, 0.562 for Courier). For images w is the chosen share of the page width and h follows from the aspect ratio. Pages with a /Rotate entry are handled in their displayed orientation, so a landscape scan gets the same diagonal as an upright page. The preview draws the same geometry on a canvas over a pdf.js rendering of page 1.
Limits
- Text uses the PDF standard fonts (Helvetica, Times, Courier in bold), which cover Latin-1 plus common typographic symbols – no Cyrillic, Greek or CJK text.
- The watermark is drawn above existing content; it does not go behind it and it is not a separate layer, so a viewer cannot switch it off.
- It is a visual mark, not a security feature: anyone with an editor can remove it.
- Encrypted PDFs are refused; unlock them first.
Sources: pdf-lib – drawText / drawImage options, PDF 32000-1:2008 – 8.4.5 Graphics state parameter dictionaries (CA/ca), Adobe Font Metrics for the standard 14 fonts.
Questions
- Can the watermark be removed later?
- Yes, by anyone with a PDF editor, because it is ordinary page content. Use it to label documents, not to protect them.
- Why does the preview look slightly different from the result?
- The preview is drawn with your system's sans-serif, serif or monospace font, while the PDF embeds the standard Helvetica, Times or Courier metrics. Position, size, angle and opacity are computed identically.
- How do I put a logo in the corner of every page?
- Choose "Image or logo", drop a PNG, set the width to 15–25%, rotation 0 and position "Bottom right" (or any corner). Keep the opacity at 100% if the logo should not look faded.
- Can I watermark only some pages?
- Yes – type a selection in "Pages", for example 2- to skip the cover or 1, 5, 9 for specific pages.