Fix
Image watermarks (and all overlays) drew flipped or off-center on pages that the viewer rotates via /Rotate, and the page-content isolation could be defeated by malformed source streams.
Rotated pages (/Rotate 90 / 180 / 270)
Page content is drawn in unrotated user space and the viewer applies /Rotate on top, so an overlay emitted naively inherited that rotation — a 45° watermark flipped to 135° on a 90° page. Editor.Apply now prepends the inverse-rotation matrix, letting overlay coordinates be expressed in displayed space (the same space Page.Search returns matches in), so the overlay renders identically regardless of page rotation.
The matrix is conjugated with the MediaBox origin — M = T(x0,y0) · R⁻¹ · T(-x0,-y0) — so it is correct on non-zero-origin pages and reduces to the bare rotation when the origin is (0,0). The forward rotation in text extraction carries the same origin offset, so Search/RedactText coordinates round-trip exactly through the overlay matrix.
Malformed / unbalanced content
isolateExistingContent now pads unbalanced q/Q and BDC|BMC/EMC nesting from broken producers into a well-formed, balanced stream, so the rewrite no longer emits a stack underflow that Acrobat flags as "An error exists on this page." Nesting is counted through the shared Lexer, so operator-like bytes inside comments, strings, dicts, and inline-image data are never miscounted.
Truncated deflate streams
decompress recovers xref/object streams that producers terminate with a sync-flush marker (00 00 FF FF), omitting the final block + Adler-32 checksum — io.ReadAll previously returned ErrUnexpectedEOF and discarded a fully-decoded stream. Decoded bytes are now kept (matching pdf.js / mutool / pikepdf), while a stream truncated before any block decodes still surfaces the error rather than passing as an empty stream.
CLI
cmd/watermark gains -skip-first / -skip-last to leave the cover / back page un-watermarked, and sizes/centers against displayed dimensions on quarter-turn pages.
Verification
- New tests:
TestRotateOverlaySpace,TestRotateOverlaySpaceCentersVisually,TestOverlayRoundTripsRotatedTextSpace,TestOverlayIsolatesExistingCTM,TestOverlayBalancesMalformedContent,TestOverlayClosesUnclosedMarkedContent,TestDecompressSyncFlushTruncation,TestDecompressTruncatedBeforeAnyBlock. - Validated on a real 53-page spec pack: rotated pages and flip-CTM pages render upright; first/last skipped with the new flags; all output pages balanced.
- Fix watermark orientation on rotated and malformed pages by @razvandimescu in #16
Full Changelog: v0.9.2...v0.9.3