Skip to content

[FEAT] PDF output for mooring reports (report --pdf) + print-layout fixes - #69

Merged
eleanorfrajka merged 1 commit into
mainfrom
pdf-report
Aug 12, 2026
Merged

[FEAT] PDF output for mooring reports (report --pdf) + print-layout fixes#69
eleanorfrajka merged 1 commit into
mainfrom
pdf-report

Conversation

@eleanorfrajka

Copy link
Copy Markdown
Collaborator

Summary

Wires up single-file PDF output for mooring reports and fixes the print layout so the merged PDF is usable on A4. The per-page HTML reports remain the single source of truth; the PDF is a post-processing step (WeasyPrint) that renders the existing pages, applies a print stylesheet, and concatenates them — report generation and the Jinja templates are unchanged except for one genuine consistency bug fixed along the way.

The combine logic (oceanarray/report/_pdf.py, combine_mooring_pdf) existed from an earlier session but was unreachable: not exported, not in the CLI, no install path for its dependency. This PR closes those gaps and then makes the rendered output actually fit the page.

PDF wiring

  • New CLI flag oceanarray report MOORING --pdf — combines the generated HTML pages into {mooring}_report.pdf (reading order summary → per-instrument → stack → grid; only pages that exist are included). --all also builds the PDF.
  • New optional extra pdfpip install oceanarray[pdf] installs WeasyPrint (kept out of core because it pulls in native libs: pango, cairo, gdk-pixbuf).
  • combine_mooring_pdf exported from oceanarray.report.
  • Output directory is resolved through a single shared helper paths.resolve_report_dir (--output-dir--report-dir/{mooring}proc/{mooring}/report/), called by both the CLI PDF path and MooringReport.generate() so the PDF always reads exactly where the HTML was written (no drift).
  • --array + --pdf warns that PDF isn't supported in array mode (the array index is HTML-only) rather than silently ignoring the flag.

Print-layout fixes (all in _pdf._PRINT_CSS unless noted)

These correct WeasyPrint-vs-browser divergences without changing the on-screen HTML:

  • Figure widths — the templates already cap figures via the .fig convention (inline max-width:50%/33%/300px, etc.). An earlier img { max-width:100% !important } in the print CSS was overriding all of them and blowing every plot up to full page; removed the !important (kept a non-important max-width:100% overflow ceiling) so the per-figure caps win again.
  • Metadata header.meta-grid uses repeat(auto-fill, minmax(...)), which WeasyPrint collapses to one column; forced a fixed 3-column layout in print.
  • Status pills (§2 pipeline) — shrunk .badge/.arrow and set the pipeline flex-wrap: nowrap so each instrument's status fits on one line.
  • Copy-yaml boxes (§3.5) — <textarea rows="2"> rendered too short and clipped the second line; forced enough height.
  • Tables — denser type + tighter padding in print; wide <th> allowed to wrap; body-text measure capped (~78ch) so explanatory notes don't run the full page width.
  • Sensor-calibration font (§5, template fix in _mooring.py) — removed a stray inline font-size on the Model cell so it matches the rest of the table (fixes both screen and PDF).

Housekeeping

  • .gitignore: ignore generated report output under tests/fixtures/proc/*/report/ (multi-MB HTML + PDFs) so it never enters history.

Tests

  • tests/unit/test_pdf_report.py: reading-order resolution; empty-dir FileNotFoundError; PDF render (valid %PDF-); custom output path; real Jinja summary rendered to PDF; and the cmd_report --pdf CLI path end-to-end + --dry-run. Render tests gated on importorskip("weasyprint").
  • tests/unit/test_cli.py: --pdf parser assertions.

Docs

reports.rst (new "PDF output" section), cli_reference.rst (--pdf flag), project_structure.md (_pdf.py).

Exit-code behaviour (no breaking change)

--all now also builds the PDF, but treats it as best-effort: if WeasyPrint isn't installed it warns and still returns 0 on the (successful) HTML, so existing report --all callers/CI without the pdf extra keep working. Only an explicit --pdf that cannot be honoured returns non-zero (you asked for a PDF and didn't get one). Locked by a test that mocks WeasyPrint away and asserts --all → 0, --pdf → 1.

@eleanorfrajka
eleanorfrajka merged commit 03dd106 into main Aug 12, 2026
9 checks passed
@eleanorfrajka
eleanorfrajka deleted the pdf-report branch August 12, 2026 07:52
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