Skip to content

render_pdf

Mojo function 🡭

render_pdf

fn def render_pdf[C: ChartLike](plot: C) -> PdfCanvas

Render plot into a one-page PdfCanvas sized plot.canvas_width() by plot.canvas_height() points and return it; render_svg()’s counterpart for a print-ready document (#372).

One layout unit is one PDF point, 1/72 inch, which is the whole physical-size contract: a 640 by 420 chart is a 640 by 420 point page, 8.89 by 5.83 inches. size_inches()/size_mm() say it the other way round. Nothing is resampled on the way out, because nothing is a pixel: paths stay paths and text stays text, embedded as a font subset so a label is selectable and searchable rather than a picture of itself.

What an export promises is the same glyphs, not the same bytes (#631). The subset embedded here is cut from whichever copy of the family the machine has, and two packagings of one family – DejaVu from apt and from brew, say – agree on every outline while differing in the hinting programs they carry. So the same chart exported on two machines draws identically and compares byte-for-byte unequal, and a build that diffs or caches PDFs should compare the rendering rather than the file.

Byte-identity would mean shipping a font rather than resolving one, which is a packaging decision and not one this contract makes. The font is most of a small document – a two-word label embeds roughly 12 KB of a 14 KB file – so a byte comparison is mostly a comparison of the machine’s font anyway.

A family the machine does not have raises rather than substituting silently, so a wrong font is never quietly embedded.

Theme.scale still multiplies every font size, margin and stroke width as it does on the other backends, so it changes how large the furniture is on the page rather than how many pixels it gets. The raster supersample factor has no meaning here and is ignored.

Parameters:

  • C (ChartLike)

Args:

  • plot (C): The chart to render.

Returns:

PdfCanvas: The finished document, ready for canvas.vector.pdf.write_pdf or the save() path that wraps it.

Raises:

Error: Whatever rendering the plot raises.

fn def render_pdf(figure: Figure) -> PdfCanvas

Render a composite Figure to a one-page PDF; render_pdf(plot)’s counterpart, over render_grid_pdf() (#697).

Args:

  • figure (Figure): The composite chart.

Returns:

PdfCanvas: The finished document.

Raises:

Error: Whatever render_grid_pdf() raises for its layout.