toyplot.reportlab.pdf module

Functions to render PDF documents using ReportLab.

toyplot.reportlab.pdf.render(canvas, fobj=None, width=None, height=None, scale=None)[source]

Render the PDF representation of a canvas using ReportLab.

Because the canvas dimensions are specified explicitly at creation time, they map directly to real-world units in the output PDF image. Use one of width, height, or scale to override this behavior.

Parameters:
  • canvas (toyplot.canvas.Canvas) – Canvas to be rendered.

  • fobj (file-like object or string) – The file to write. Use a string filepath to write data directly to disk. If None (the default), the PDF data will be returned to the caller instead.

  • width (number, string, or (number, string) tuple, optional) – Specify the width of the output image with optional units. If the units aren’t specified, defaults to points. See Units for details on unit conversion in Toyplot.

  • height (number or (number, string) tuple, optional) – Specify the height of the output image with optional units. If the units aren’t specified, defaults to points. See Units for details on unit conversion in Toyplot.

  • scale (number, optional) – Scales the output canvas by the given ratio.

Returns:

pdf – PDF representation of canvas, or None if the caller specifies the fobj parameter.

Return type:

PDF data, or None

Examples

>>> toyplot.reportlab.pdf.render(canvas, "figure-1.pdf", width=(4, "inches"))