Custom Radio Export Names: the API Says OK and Changes Nothing, the xref Layer Renames Them For Real
Setting field_value to "A", "B", and "C" on the PyMuPDF-built radio kid returned OK all three times, and after every attempt the kid's state dict still read {'normal': ['Off', 'Yes'], 'down': None}: the API accepted each custom name and changed nothing. The API door — widget.field_value = "A" — returned OK on all three attempts and altered nothing: each kid's states still read {'normal': ['Off', 'Yes'], 'down': None} afterward. The xref door — rewriting each kid's AP/N appearance-state dict from <</Off 18 0 R/Yes 19 0 R>> to <</Off 18 0 R/A 19 0 R>> — renamed the states, and the rename survived a save-reopen cycle: the reopened group reads Off/A, Off/B, Off/C. After that rename, every kid accepted its own state name, PyMuPDF read all three back as on (A, B, C), and pypdf's parent field read 'C'.
Two doors to the same rename
Installed with pip install pymupdf pypdf, no pins; the versions printed inside this run's own logs: pypdf 6.20.0 | PyMuPDF 1.28.2. The group is Day 17's deterministic build — three kids named plan, field_value = False before each add_widget — so construction is not a variable on this page. Both kids of the rename attempt ran in one process against the same saved file, and each attempt's verbatim line is quoted below.
| Attempt | Verbatim from this run | What the saved file shows after reopen |
|---|---|---|
API: field_value = "A"/"B"/"C" on kid 0 | API set field_value 'A' -> OK, kid0 states now: {'normal': ['Off', 'Yes'], 'down': None} — and the same shape for 'B' and 'C' | states unchanged: Off/Yes |
xref: xref_set_key(x, "AP/N", ...) per kid | kid xref 5 AP/N raw: ('dict', '<</Off 18 0 R/Yes 19 0 R>>') → renamed /Yes -> /A new dict: <</Off 18 0 R/A 19 0 R>> — same for B and C on xrefs 8 and 11 | {'normal': ['Off', 'A']}, {'normal': ['Off', 'B']}, {'normal': ['Off', 'C']} |
The API attempt's OK-with-no-change is recorded as a symptom, without a mechanism attached: three calls accepted three custom names and the state dicts did not move.
Filling the renamed group
With the states renamed, the fill sequence ran one write per kid — A, then B, then C — each targeting its own state name. Every write returned OK. The readbacks afterward split by layer, and this is where the page's second measured inconsistency sits:
| Layer | Verbatim readback |
|---|---|
| PyMuPDF kid values | [('plan', 'A'), ('plan', 'B'), ('plan', 'C')] — all three read as on |
pypdf parent field (get_fields()) | {'plan': 'C'} — the last write |
pypdf annotation /AS walk | /AS: /A | /Rect: [72.0, 180.0, 92.0, 200.0], /AS: /B | /Rect: [72.0, 140.0, 92.0, 160.0], /AS: /C | /Rect: [72.0, 100.0, 92.0, 120.0] |
One inconsistency with Day 18 stays exactly as printed: there, pypdf's parent field read /Off on a one-selection fixture; here it reads 'C' on a three-selection one. Between the two runs two variables moved at once — the number of selections (1 vs 3) and the state names on the fixtures (Yes vs renamed A/B/C) — so no cause is assigned; both readbacks stand as measured. Day 18's own page already limits itself the same way.
The calls as run
import pypdf, pymupdf
print("RUN VERSIONS pypdf:", pypdf.__version__, "| pymupdf:", pymupdf.__version__)
# ran: RUN VERSIONS pypdf: 6.20.0 | pymupdf: 1.28.2
# build (Day 17's flip condition) and save abc_build.pdf
doc = pymupdf.open()
page = doc.new_page(width=612, height=300)
for y in (100, 140, 180):
w = pymupdf.Widget()
w.rect = pymupdf.Rect(72, y, 92, y+20)
w.field_type = pymupdf.PDF_WIDGET_TYPE_RADIOBUTTON
w.field_name = "plan"
w.field_value = False
page.add_widget(w)
doc.save("abc_build.pdf")
# the xref rename, per kid
d = pymupdf.open("abc_build.pdf")
pg = d[0]
for wd, target in zip(pg.widgets(), ("A", "B", "C")):
apn = d.xref_get_key(wd.xref, "AP/N")
# ran: ('dict', '<>') on xref 5; xrefs 8 and 11 analogous
d.xref_set_key(wd.xref, "AP/N", apn[1].replace("/Yes", "/" + target))
d.save("abc_renamed.pdf")
# reopened states, verbatim: {'normal': ['Off', 'A']} / ['Off', 'B'] / ['Off', 'C']
# fill the renamed group, one write per kid
d = pymupdf.open("abc_renamed.pdf")
for wd, target in zip(d[0].widgets(), ("A", "B", "C")):
wd.field_value = target; wd.update()
# ran: set A OK / set B OK / set C OK
d.save("abc_filled.pdf")
print([(w.field_name, w.field_value) for w in pymupdf.open("abc_filled.pdf")[0].widgets()])
# ran: [('plan', 'A'), ('plan', 'B'), ('plan', 'C')]
print({k: str(v.get('/V')) for k, v in PdfReader("abc_filled.pdf").get_fields().items()})
# ran (pypdf): {'plan': 'C'}
What the rename buys downstream
The annotation layer is where the payoff shows: after the rename, each kid's /AS carries a meaningful label (/A, /B, /C) instead of the generic /Yes Day 17 and Day 18 recorded — so a reader walking annotations now gets option identity in the state name itself, with the rectangle still alongside. What the rename does not do, as-run: it does not enforce one-kid-on semantics at the kid level — all three kids read back on after the three-write sequence, while the parent field holds only the last write. Both facts are quoted above; nothing between them is inferred.
Open items on this page
- Why the API path accepts custom names without applying them — not run; the symptom (three OKs, zero state change) is recorded verbatim and no code-level cause was chased.
- Whether Day 18's parent-
/Offversus today's parent-'C'is selection-count-caused or state-name-caused — not run; two variables moved between those runs at once and no isolation experiment was executed, so both readbacks stay unattributed. - Hand-built contrast fixture (Day 15's raw A/B/C PDF) — not run; the archived fixture file was not present in this sandbox (
os.path.existsprintedFalse), and rebuilding it raw was outside today's scope. - Appearance streams for the renamed states — not run; renaming
AP/Nkeys remaps state names onto the existing XObjects, and no new stream was generated or rendered for visual verification. - XFA forms — carried unchanged from Day 14: no offline XFA fixture.
Both code blocks are the run itself: versions printed first, outputs inline, logs kept as day19_rename_log.txt and day19_fill_log.txt.