render_pdf#

Import

from scenet import render_pdf

Defined in

scenet.emit.pdf (source)

Install

pip install scenet

Since

0.13

Stability

Public: follows semantic versioning. Below 1.0, a minor release may change it, and the CHANGELOG says how.

scenet.emit.pdf.render_pdf(pages, panels, *, fonts=None, images=None, live_text=False, mono=False)[source]#

Draw a document as a print PDF.

One PDF page per page, its TrimBox the page; or, for a document with no pages, one per panel at its own size. Lettering is 100% K and overprints; see the module docstring for every other ink.

Parameters:
  • pages (Sequence[PageCore]) – The document’s pages, in order – empty for a document without any.

  • panels (Mapping[str, PanelCore]) – Every panel’s compiled Core, by name.

  • fonts (Mapping[str, FontMetrics] | None) – The declared fonts the panels were lettered in, by digest.

  • images (Mapping[str, bytes] | None) – The supplied pictures’ bytes, by digest – what Book.images holds. A picture is always carried inside the PDF, pixels unchanged; see scenet.emit.pdf_images.

  • live_text (bool) – Letter balloons and captions in text, their faces embedded, rather than in outlines. Each glyph lands where its outline would; a face whose licence forbids embedding stays in outlines, as print_notes() says.

  • mono (bool) – Print a tinted panel in its greys, as --mono draws it, rather than in its colours’ CMYK twins: the same file as the panel’s palette: mono twin.

Return type:

bytes

Returns:

The PDF’s bytes.

Raises:

RenderError – A page places a panel that was not given, a Core names a font that was not, a picture’s bytes were not handed over, or a picture is one no PDF reader decodes.

Note

A page unit prints as 0.1 mm, and lettering is on the black plate. No PDF/X conformance is claimed. The same pages and arguments give the same bytes.

Example

>>> from scenet import compile_book, render_pdf
>>> book = compile_book("cast: {a: {reference: alice}}\npanels: {one: {}}")
>>> cores = {name: result.core for name, result in book.panels.items()}
>>> render_pdf(book.pages, cores)[:8]
b'%PDF-1.6'

See also

render_pages, the same pages as SVG.