🧾 Usage¶
Instantiate the Class¶
Import the module:
from thermalprinter import ThermalPrinter
So the module can be used as a context manager:
with ThermalPrinter() as printer:
# ...
Or:
printer = ThermalPrinter()
Refer to the ThermalPrinter() documentation for potential keyword-arguments.
A World of Infinite Possibilities¶
An example is better than a thousand words:
with ThermalPrinter() as printer:
printer.out("Show time, here comes the demonstration!")
printer.feed()
printer.demo()
Where you can see the ThermalPrinter.demo() source code right here:
def demo(self) -> None:
"""Show time!
Demonstrate printer capabilities.
.. versionadded:: 1.0.0
"""
# Image (requires the PIL Image library)
self.feed()
self.image(GNU_FILE)
self.feed()
# Barcode
self.barcode(
"012345678901",
BarCode.EAN13,
width=3,
height=80,
left_margin=2,
position=BarCodePosition.BELOW,
)
# Style
self.out("Bold", bold=True)
self.out("Double height", double_height=True)
self.out("Double width", double_width=True)
self.out("Font B mode", font_b=True)
self.out("Inverse", inverse=True)
self.out("Rotate 90°", rotate=True, codepage=CodePage.ISO_8859_1)
self.out("Left blank", left_blank=10)
self.out("Left margin", left_margin=5)
self.out("Size LARGE", size=Size.LARGE)
self.out("Strike", strike=True)
self.out("Underline", underline=Underline.THIN)
self.out("Upside down", upside_down=True)
# Chinese (almost all alphabets exist)
self.out("现代汉语通用字表", chinese=True, chinese_format=Chinese.UTF_8)
# Greek (excepted the ΐ character)
self.out("Στην υγειά μας!", codepage=CodePage.CP737)
# Persian (check the recipes documentation for this to work)
self.out("سلام. این یک جمله فارسی است\nگل پژمرده خار آید", persian=True)
# Other characters
self.out(b"Cards \xe8 \xe9 \xea \xeb", codepage=CodePage.CP932)
# Accent
self.out(
"Voilà !",
codepage=CodePage.ISO_8859_1,
justify=Justify.CENTER,
strike=True,
underline=Underline.THICK,
)
self.feed(2)