Print and PDF handoff

I wanted to know what Chrome puts into a printed page or PDF when live HTML sits inside a drawable canvas. Press Print (or Cmd/Ctrl+P) to print both cards side by side and test text selection, 800% zoom on the SVG barcode, and the clickable link. Toggle Simulate print handoff to watch moveBefore() pull the right card out into plain DOM and return it without dropping typed text or checkbox state.

Right card: in <canvas>
1. Canvas output Stays in <canvas> on print
Spec #HIC-2026-412A

Dispatch Pass

Origin
html-in-canvas.page
Strategy
Stays in <canvas layoutsubtree>

Vector check: 11px body copy, kerning AV Ta fi, 0.5pt rules. Select this sentence in the PDF and click the link above.

HIC-412-CANVAS-01 2026-11-26
2. moveBefore() DOM output In <canvas> on screen
Spec #HIC-2026-412B

Dispatch Pass

Origin
html-in-canvas.page
Strategy
beforeprint + moveBefore()

Vector check: 11px body copy, kerning AV Ta fi, 0.5pt rules. Select this sentence in the PDF and click the link above.

HIC-412-DOM-HANDOFF-02 2026-11-26

 

Show the code the two cards, the canvas paint effect, the beforeprint handoff, the print CSS
  1. The two cards. Two copies of one dispatch card inside drawable canvases, with a sibling #print-host ready for the right card.
  2. Drawing on screen. Sizes the backing store with device-pixel-content-box, draws crop marks, tilts the card with 5-argument drawElementImage(), then adds paper grain and an angled stamp.
  3. The beforeprint and afterprint handoff. Moves the right card out with moveBefore() (with an appendChild() fallback), records state survival, and moves it back with requestPaint().
  4. Print styles. Hides site chrome and places both cards side by side in the printed page or PDF.

How it works

Both cards start inside a <canvas content="drawable" layoutsubtree>. On screen, the 2D paint handler renders each card onto a warm drafting mat with corner crop marks, a slight tilt, paper grain and a red "CANVAS 2D" rubber stamp. That makes it obvious on screen when a card is painted by a canvas versus sitting in plain DOM.

When you open Print or Save as PDF, two things happen at once. The left card stays inside #raw-canvas so the PDF captures whatever Chrome's print pipeline emits for a drawable canvas. On the right card, the beforeprint listener (and window.matchMedia('print') as a backup) calls printHost.moveBefore(card, null) to move the live <article> out of #handoff-canvas into #print-host.

Because #print-host is kept rendered rather than display: none, moving the card with moveBefore() preserves the typed text in "Recipient name", the text selection range, the checkbox state, and keyboard focus. When the print dialog closes, afterprint un-hides #handoff-canvas first, calls handoffCanvas.moveBefore(card, null), and calls handoffCanvas.requestPaint() so the styled canvas snaps back.

In a browser without moveBefore(), the handoff falls back to appendChild(). In a browser without HTML-in-canvas, the script moves both cards out of their canvases into plain HTML so neither shows up as an empty box.

Live checks

These run on their own fixtures in the corner of the window. They never touch the cards above and never call window.print().

Findings