PDFPipe

Marks on the page / Watermark

A DRAFT watermark on every page that does not obscure the text

A large word set diagonally behind the content on every page, used to mark a document as a draft, a copy or a specimen.

Why this block is harder than it looks

Three things go wrong. It has to be on every page, which means it belongs to the page rather than to the content, and a single positioned element in the body appears once. It has to be behind the text, which means a stacking context that most people get wrong by putting it after the content in the source and giving it a positive z-index. And it has to be visible on paper without making the text unreadable, which is a tension that people usually resolve by making it so faint it disappears when print backgrounds are off, at which point it is not there at all.

The decisions that make it work

Reasons rather than a description of the code. Each of these is a choice that has a wrong answer, and the wrong answer is usually the default.

  • Repeat it per page using a page background or a fixed-position element, and confirm it actually repeats, because a positioned block in the flow will not.
  • Set it as text with a large size and low opacity rather than as an image. Text stays sharp at any print resolution and weighs nothing.
  • Keep it behind the content with a negative z-index and a positioned ancestor, and check by looking at the output rather than at the source order.
  • Use a grey around 12 to 18 percent rather than a coloured tint at low opacity. On a monochrome printer a light colour becomes a light grey anyway, and choosing the grey yourself means you know what you get.
  • Set print-color-adjust: exact on it, because a watermark is exactly the kind of background a print pipeline drops.
  • Rotate about 45 degrees around the centre and keep it clear of the margins, so it does not collide with the folio or the running header.

The fragment

Markup and the CSS it needs, and nothing else. It expects a document that already has a page rule and a base stylesheet, so paste it into one rather than opening it on its own.

html
<div class="watermark" aria-hidden="true">DRAFT</div>

<style>
  .watermark {
    position: fixed;               /* repeats on every page in paged output */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
    z-index: -1;                   /* behind the content */
    font-size: 96pt;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: #d9d9d9;                /* a chosen grey, not a faint colour */
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
    pointer-events: none;
    white-space: nowrap;
  }
  body { position: relative; }     /* gives the negative z-index something to sit behind */
</style>

What breaks when it is built the obvious way

Relying on opacity alone to keep it out of the way. Opacity is a transparency operation, and a document that has to be PDF/A-1 conformant cannot contain any transparency at all, so the watermark is the thing that fails the file. A flat light grey looks the same and involves no transparency.

How to prove it survived pagination

Render a three-page document and confirm the mark is on all three, in the same place, behind the text. Then print one page on a real printer with print backgrounds left at their default: if the watermark vanishes, print-color-adjust is missing or the grey is too light.

Where it sits in a finished document

This page is one block. The document it belongs to has a page rule, a base stylesheet, a header and everything else around it, and repeating all of that here would make thirty pages that say the same thing. The services agreement template is a complete file with this block already in it, so take that and change the fragment rather than assembling one from parts. The property doing most of the work here is covered on its own page, with the support caveats that belong there rather than here.

Frequently asked

Will this fragment work on its own?

Not as a whole document. It has no page rule, no margins and no base type, because those belong to the document rather than to the block, and duplicating them in every fragment would mean thirty copies to keep in step. Paste it into a template that already has them.

Why does it look right in a browser and wrong in the PDF?

Because a browser window is one continuous surface and a document is a stack of fixed rectangles. Nothing in a scrolling view exercises a page boundary, so every break rule in the fragment is inert until the content is paginated. Render the real thing with enough content to cross two or three boundaries, then look.

Do I need a special option on the render request for this?

No. Everything on this page is CSS and markup, which is your side of the boundary. What the render has to give you is a real page size with real margins, and after that the layout is decided by the stylesheet.

Other parts of a document

The blocks that sit next to this one, and one from the next group along so you are not sealed inside a single kind of problem.

Paste the fragment into the playground inside a page rule and see what it does at a real page size. That is the only way any of this gets confirmed.