Skip to content

Commit 492dae8

Browse files
Wire up PDF output (port of upstream PR wireviz#367)
Implements the ``pdf`` output format that's been a TODO stub since v0.4.1. Pipes the graph through Graphviz's PDF renderer (``graph.pipe(format="pdf")``) and dispatches the bytes the same way PNG goes — to a file in normal mode, to ``sys.stdout.buffer`` in stdout mode. Usage: wireviz -f P harness.yml # produces harness.pdf cat harness.yml | wireviz -f P -O - - # stdout, binary CLI flag changes: * ``"P": "pdf"`` un-commented in ``format_codes`` (use ``-f P``) * "PDF output is not yet supported" stderr warning removed from Harness.output() Adapted from wireviz#367 (originally by @tobiasfalk, targeting upstream ``dev``). The upstream patch went through the old ``graph.render()`` + temp-file path — this port uses the in-memory ``graph.pipe()`` wired up by the stdin/stdout refactor (PR wireviz#321), so PDF works in both file mode AND stdout mode without extra plumbing. Verified: * ``wireviz -f P harness.yml`` produces a valid PDF (file 1.7). * ``cat harness.yml | wireviz -f P -O - -`` writes valid PDF to stdout. * build_examples.py: deterministic outputs (.gv, .bom.tsv) byte- identical (no example .yml has been switched to request PDF rendering — keeping that out of the regression baseline since PDF bytes from graphviz vary by version). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c8d9469 commit 492dae8

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/wireviz/Harness.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,6 @@ def output(
698698
if "csv" in fmt:
699699
# TODO: implement CSV output (preferably using CSV library)
700700
sys.stderr.write("CSV output is not yet supported\n")
701-
if "pdf" in fmt:
702-
# TODO: implement PDF output
703-
sys.stderr.write("PDF output is not yet supported\n")
704701

705702
if filename is None:
706703
# stdout mode — emit each rendered format in the user-requested order
@@ -763,6 +760,9 @@ def _render(
763760
png_bytes = graph.pipe(format="png")
764761
outputs["png"] = png_bytes
765762

763+
if "pdf" in fmt:
764+
outputs["pdf"] = graph.pipe(format="pdf")
765+
766766
if "gv" in fmt:
767767
outputs["gv"] = graph.source
768768

src/wireviz/wv_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"g": "gv",
1919
"h": "html",
2020
"p": "png",
21-
# "P": "pdf",
21+
"P": "pdf",
2222
"s": "svg",
2323
"t": "tsv",
2424
}

0 commit comments

Comments
 (0)