Skip to content

Add text: watermarks, page numbers, Bates stamps - #3

Merged
tannevaled merged 1 commit into
mainfrom
text-stamps
Aug 25, 2026
Merged

Add text: watermarks, page numbers, Bates stamps#3
tannevaled merged 1 commit into
mainfrom
text-stamps

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

The other half of what people do to a PDF they have: write on it. One
primitive — a line of text, a face, a size, a colour, a transparency, an angle
and one of nine places — with the three things people actually ask for built on
it. The text may name what it is drawn on: {page}, {pages}, and {n} for a
counter that advances once per page, which is what a serial numbering scheme
needs.

Nothing is embedded. The four faces every viewer is required to have are enough
for a watermark or a page number, so a stamp costs about a kilobyte and works
everywhere. Their widths are Adobe's own, exact through printable ASCII, with a
Latin-1 letter taking the width of the letter it is built on — which is true of
these faces. Text is encoded as WinAnsi, and a character that encoding has no
room for is dropped rather than drawn as something else.

A stamped page keeps everything it had. Its own content streams are referenced
unchanged, wrapped in a save and a restore so whatever state they leave behind
cannot reach the text, and the resources are rebuilt as a dictionary of this
file's own — because the page may be sharing them with pages that are not being
stamped. The text goes in the page's own box, so on a page carrying a rotation
it turns with the page, as the page's own layout does. A page used as a tile is
wrapped first, so its text lands in the space the page is displayed in.

Verified across the corpus: for each of the 118 833 files, numbering every page
has to leave the page's own content stream in the file byte for byte, draw the
number, name a face the file carries, and put the text inside the page. All
118 833 hold — after the campaign found two real defects. A /Contents written
as a reference to an array, which 2 194 files do, lost the page's content
entirely; and 950 pages are smaller than the default margin, which put their
text off the page. Both are fixed, and the earlier 118 833-file and 1 959-file
checks still pass.

What this cannot yet check is what the text looks like. That needs a
rasteriser, and when there is one these stamps should be checked in pixels.

Exact 100% statement coverage over the package and the command, go vet clean,
nine cross-compilation targets.

The other half of what people do to a PDF they have: write on it. One
primitive — a line of text, a face, a size, a colour, a transparency, an angle
and one of nine places — with the three things people actually ask for built on
it. The text may name what it is drawn on: {page}, {pages}, and {n} for a
counter that advances once per page, which is what a serial numbering scheme
needs.

Nothing is embedded. The four faces every viewer is required to have are enough
for a watermark or a page number, so a stamp costs about a kilobyte and works
everywhere. Their widths are Adobe's own, exact through printable ASCII, with a
Latin-1 letter taking the width of the letter it is built on — which is true of
these faces. Text is encoded as WinAnsi, and a character that encoding has no
room for is dropped rather than drawn as something else.

A stamped page keeps everything it had. Its own content streams are referenced
unchanged, wrapped in a save and a restore so whatever state they leave behind
cannot reach the text, and the resources are rebuilt as a dictionary of this
file's own — because the page may be sharing them with pages that are not being
stamped. The text goes in the page's own box, so on a page carrying a rotation
it turns with the page, as the page's own layout does. A page used as a tile is
wrapped first, so its text lands in the space the page is displayed in.

Verified across the corpus: for each of the 118 833 files, numbering every page
has to leave the page's own content stream in the file byte for byte, draw the
number, name a face the file carries, and put the text inside the page. All
118 833 hold — after the campaign found two real defects. A /Contents written
as a reference to an array, which 2 194 files do, lost the page's content
entirely; and 950 pages are smaller than the default margin, which put their
text off the page. Both are fixed, and the earlier 118 833-file and 1 959-file
checks still pass.

What this cannot yet check is what the text looks like. That needs a
rasteriser, and when there is one these stamps should be checked in pixels.

Exact 100% statement coverage over the package and the command, go vet clean,
nine cross-compilation targets.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 958f69d into main Aug 25, 2026
1 check passed
@tannevaled
tannevaled deleted the text-stamps branch August 25, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant