热敏打印机驱动程序和模板
linemode的Python项目详细描述
用于与线模式热敏打印机通信的python库。 目前只适用于支持星线模式协议的打印机,但应该可以添加对其他类似打印机的支持。
还提供了一个模块,用于将页面的XML描述编译为命令列表。
在Newman Online Ltd开发并经许可开放源代码。
示例
基本,无模板系统:
fromlinemodeimportopen_printerprinter=open_printer('star+lpt:///dev/usb/lp0')printer.run_commands([('fontsize-large'),('select-bold'),('write',"Hello world\n"),('cut-through'),])
运行模板:
fromlinemodeimportopen_printerfromlinemode.renderersimportxmlprinter=open_printer('star+lpt:///dev/usb/lp0')printer.run_commands(xml.render(""" <document> <line> <bold>Hello world</bold> </line> </document> """))
带着金贾:
fromjinja2importTemplatefromlinemodeimportopen_printerfromlinemode.renderersimportxmlprinter=open_printer('star+lpt:///dev/usb/lp0')# jinja2 templatetemplate=""" <document> {% for potatoes in [1, 2, 3, 4] %} <line> {{ potatoes }} potato </line> {% endfor %} </document> """# line mode printer documentdocument=Template(template).render()# iterator of generic printer instructionscommands=xml.render(document)# printer specific compiled representationprogram=printer.compile(commands)printer.execute(program)
命令语言
打印机驱动程序接受一个iterable命令元组。 元组应包含一个命令名,后跟任意数量的基元参数。 为了方便起见,只包含命令名的元组可以替换为命令名。
支持以下命令:
- reset
- 将所有内容重置为初始状态。
- select-bold/cancel-bold
- 切换打印粗体文本。
- select-highlight/cancel-highlight
- 切换黑白打印而不是黑白打印。
- fontsize-small/fontsize-medium/fontsize-large
设置当前行和所有后续行的行高。 如果不是在新行的开头发送,则行为是未定义的。 字符宽度应保持不变。
默认值:fontsize-small
- write <string>
- 打印Unicode字符串的内容。 如果任何字符不受支持,它们将被替换为'?'.
- barcode <style> <data>
- 待办事项
- newline
- 刷新行缓冲区并开始新的行。
- cut-through
- 在下一个标记处创建切口
- cut-partial
- 在下一个标记处创建穿孔切口
- cut-through-immediate
- 在当前光标位置创建剪切
- cut-partial-immediate
- 在当前光标位置创建穿孔切口
错误
请使用issue tracker发布任何问题或功能请求。 欢迎拉取请求。 新司机将不胜感激。