PSDraw module¶
The PSDraw module provides simple print support for PostScript
printers. You can print text, graphics and images through this module.
- class PIL.PSDraw.PSDraw(fp: IO[bytes] | None = None)[source]¶
Sets up printing to the given file. If
fpis omitted,sys.stdout.bufferis assumed.- begin_document(id: str | None = None) None[source]¶
Set up printing of a document. (Write PostScript DSC header.)
- image(box: tuple[int, int, int, int], im: Image.Image, dpi: int | None = None) None[source]¶
Draw a PIL image, centered in the given box.
- line(xy0: tuple[int, int], xy1: tuple[int, int]) None[source]¶
Draws a line between the two points. Coordinates are given in PostScript point coordinates (72 points per inch, (0, 0) is the lower left corner of the page).
- rectangle(box: tuple[int, int, int, int]) None[source]¶
Draws a rectangle.
- Parameters:
box – A tuple of four integers, specifying left, bottom, width and height.
- setfont(font: str, size: int) None[source]¶
Selects which font to use.
- Parameters:
font – A PostScript font name
size – Size in points.
- text(xy: tuple[int, int], text: str, *, escape: bool = False) None[source]¶
Draws text at the given position. You must use
setfont()before calling this method.- Parameters:
xy – The position, in PostScript point coordinates.
text – The text to draw, encoded as Latin-1.
escape –
Whether to escape backslashes in the text. This keyword-only boolean defaults to
False, leaving backslashes unchanged for backwards compatibility. Parentheses are always escaped.Added in version 13.0.0.