fix: PDF-Endpoint setzt OpenAction auf gefundene Seite + Topbar weiter komprimiert

Vorher: /api/wahlprogramm-cite lieferte das gesamte PDF mit Highlight-Annot
auf der gefundenen Seite, aber der Browser-PDF-Viewer landete auf Seite 1.
Sieht User: 'PDF oeffnet, aber falsche Seite'.

Jetzt: doc.xref_set_key(catalog, 'OpenAction', '[<page-ref> 0 R /Fit]')
schreibt eine PDF-Open-Action ins Dokument-Catalog. Reader springt beim
Oeffnen direkt auf target_page_idx, ohne dass Browser-Hash-Anker noetig sind.

Plus: Topbar select/button padding-top/bottom 1px, links 0px (User: 'nur so
hoch wie noetig').

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dotty Dotter 2026-04-25 22:06:39 +02:00
parent 489a1915f8
commit 88f9c7db6c
2 changed files with 17 additions and 7 deletions

View File

@ -797,8 +797,7 @@ def render_highlighted_page(programm_id: str, seite: int, query: str) -> Optiona
target_page_idx = i target_page_idx = i
break break
# Volles PDF mit Highlight-Annotation. Der Browser öffnet das # Volles PDF mit Highlight-Annotation.
# vollständige Wahlprogramm; das Frontend hängt #page=N an die URL.
page = src[target_page_idx] page = src[target_page_idx]
if needle and rects: if needle and rects:
for rect in rects: for rect in rects:
@ -807,6 +806,16 @@ def render_highlighted_page(programm_id: str, seite: int, query: str) -> Optiona
annot.set_colors(stroke=(1.0, 0.93, 0.0)) # gelb annot.set_colors(stroke=(1.0, 0.93, 0.0)) # gelb
annot.update() annot.update()
# PDF-OpenAction setzen, damit der Reader direkt auf der richtigen
# Seite startet (statt Seite 1) — sonst sieht der User „PDF öffnet,
# aber falsche Seite". /Fit = passt-zur-Größe.
try:
page_xref = page.xref
catalog_xref = src.pdf_catalog()
src.xref_set_key(catalog_xref, "OpenAction", f"[{page_xref} 0 R /Fit]")
except Exception:
logger.exception("render_highlighted_page: OpenAction-Setzen fehlgeschlagen")
highlighted = bool(needle and rects) highlighted = bool(needle and rects)
try: try:
return src.tobytes(), target_page_idx + 1, highlighted return src.tobytes(), target_page_idx + 1, highlighted

View File

@ -75,12 +75,13 @@ body.v2 :focus-visible {
line-height: 1.2; line-height: 1.2;
color: var(--ecg-dark); color: var(--ecg-dark);
} }
.v2-topbar > *, .v2-topbar select,
.v2-topbar button, .v2-topbar button {
.v2-topbar select { padding-top: 1px;
padding-top: 2px; padding-bottom: 1px;
padding-bottom: 2px; margin: 0;
} }
.v2-topbar a { padding: 0; }
.v2-topbar-spacer { .v2-topbar-spacer {
flex: 1; flex: 1;