Skip to content

stepup.reprep.tile_pdf

Tile PDF figures.

Figure

The definition of a tiled figure

Attributes:

  • path_out (str) –

    The PDF output file.

  • panels (list[Panel]) –

    The list panels, instances of the Panel class.

  • fontname (str) –

    A Fontname recognized by PyMyPDF or a custom name when fontfile is specified.

  • fontfile (str | None) –

    None or the path to a ttf file. When used, specify a corresponding fontname (of your choice).

  • fontsize (float) –

    The font size to use for the labels in points.

  • label_height (float) –

    The height to use for the labels in mm.

  • padding (float) –

    The padding added added to the panels before combining them, in mm. This parameter is also used as margin between the label and the figure.

  • hshift (float) –

    An optional horizontal displacement of the panel label, in mm.

Source code in stepup/reprep/tile_pdf.py
@attrs.define
class Figure:
    """The definition of a tiled figure

    Attributes
    ----------
    path_out
        The PDF output file.
    panels
        The list panels, instances of the `Panel` class.
    fontname
        A Fontname recognized by PyMyPDF or a custom name when fontfile is specified.
    fontfile
        None or the path to a ttf file.
        When used, specify a corresponding fontname (of your choice).
    fontsize
        The font size to use for the labels in points.
    label_height
        The height to use for the labels in mm.
    padding
        The padding added added to the panels before combining them, in mm.
        This parameter is also used as margin between the label and the figure.
    hshift
        An optional horizontal displacement of the panel label, in mm.
    """

    path_out: str = attrs.field()
    panels: list[Panel] = attrs.field()
    fontname: str = attrs.field(default="hebo")
    fontfile: str | None = attrs.field(default=None)
    # Dimensions in points. (1 point = 1/72 inch)
    fontsize: float = attrs.field(default=7.0)
    label_height: float = attrs.field(default=2.0)
    padding: float = attrs.field(default=1.0)
    hshift: float = attrs.field(default=0.0)

    def info(self):
        inp = [panel.path_in for panel in self.panels]
        if self.fontfile is not None:
            inp.append(self.fontfile)
        return {"inp": inp, "out": self.path_out}

    def run(self):
        """Combine PDF figures into a single PDF with labels on top of each panel."""
        _load_pdfs(self.panels)
        for panel in self.panels:
            _add_label(panel, self)
        out = _combine_figures(self.panels)
        out.set_metadata({})
        out.del_xml_metadata()
        out.scrub()
        out.save(self.path_out, garbage=4, deflate=True, linear=True, no_new_id=True)

run()

Combine PDF figures into a single PDF with labels on top of each panel.

Source code in stepup/reprep/tile_pdf.py
def run(self):
    """Combine PDF figures into a single PDF with labels on top of each panel."""
    _load_pdfs(self.panels)
    for panel in self.panels:
        _add_label(panel, self)
    out = _combine_figures(self.panels)
    out.set_metadata({})
    out.del_xml_metadata()
    out.scrub()
    out.save(self.path_out, garbage=4, deflate=True, linear=True, no_new_id=True)

Panel

The definition of one panel in a tiled figure.

Attributes:

  • irow (int) –

    The row where the panel is located (top left corner).

  • icol (int) –

    The column where the panel is located (top left corner).

  • label (str) –

    The label to be put above the panel.

  • path_in (str) –

    The path of the PDF file with the figure.

  • nrow (int) –

    The number of rows occupied by the panel.

  • ncol (int) –

    The number of columns occupied by the panel.

Source code in stepup/reprep/tile_pdf.py
@attrs.define
class Panel:
    """The definition of one panel in a tiled figure.

    Attributes
    ----------
    irow
        The row where the panel is located (top left corner).
    icol
        The column where the panel is located (top left corner).
    label
        The label to be put above the panel.
    path_in
        The path of the PDF file with the figure.
    nrow
        The number of rows occupied by the panel.
    ncol
        The number of columns occupied by the panel.
    """

    irow: int = attrs.field()
    icol: int = attrs.field()
    label: str = attrs.field()
    path_in: str = attrs.field()
    nrow: int = attrs.field(default=1)
    ncol: int = attrs.field(default=1)
    pdf = attrs.field(default=None)