展示HN:热敏收据打印机 – Markdown 和 Web UI
Show HN: Thermal Receipt Printers – Markdown and Web UI

原始链接: https://github.com/sadreck/ThermalMarky

## ThermalMarky:为您的热敏打印机注入活力 ThermalMarky是一个旨在利用经常被遗忘的热敏收据打印机的项目。它允许您通过用户友好的WebUI、命令行界面(CLI)或直接通过HTTP请求打印Markdown格式的文本。 **主要特性:** 支持基本的Markdown(标题、粗体、下划线、列表),用于对齐、水平线和QR码的自定义标签。它已准备好Docker,简化了设置和USB权限管理。 **设置:** 需要兼容的热敏打印机(经过MUNBYN ITPP047UE-WH-UK测试)。配置涉及设置打印机连接详细信息(USB或网络)以及通过`.env`文件设置最大行数和行宽等可选参数。 **运行ThermalMarky:** 推荐使用Docker Compose。或者,可以使用Python 3.12+和所需的系统库本机运行。WebUI可以通过安全的(自签名证书)HTTPS连接访问。 在项目的GitHub页面上可以找到更多详细信息和故障排除信息。

一个 Hacker News 上的新项目 ([github.com/sadreck](https://github.com/sadreck)) 允许用户通过 Markdown 和 Web UI 控制热敏小票打印机。用户对 Markdown 的直观扩展印象深刻,例如居中文字和直接在打印格式中生成二维码。 讨论显示出人们对利用这些打印机进行实际任务(如时间跟踪和待办事项列表)的兴趣日益增长,超越了简单的收据打印。 许多评论者分享了类似的项目,包括基于 CLI 的待办事项列表打印机和数独生成器。 对话还涉及打印机硬件——特别是对经济实惠、无线 80 毫米纸打印机的需求——以及对热敏纸中化学物质的潜在健康问题(并提出了无酚替代品的建议)。 最后,用户探索了扩展对 HTML/CSS 的支持以及打印更复杂的文档(如 PDF)的可能性。
相关文章

原文

Did you ever buy a thermal receipt printer "to do cool stuff" which is now collecting dust? No? Me neither.

But if you have a friend that did, ThermalMarky is here to help by supporting basic Markdown features and a basic WebUI to go with it.

  • Markdown Support: Headers, Bold, Underline, and Lists.
  • Enhanced Formatting: Custom tags for alignment ([align=center]), horizontal lines, and QR Codes.
  • Web UI: A clean interface with built-in editor shortcuts.
  • CLI Mode: Print directly from your terminal or pipe content into it.
  • Docker Ready: You know exactly what this means.

Unfortunately due to the different types of thermal printers out there, you will need to make sure your printer works before trying to use ThermalMarky.

This project has only been tested with MUNBYN Thermal Printer / ITPP047UE-WH-UK.

Rename .env.example to .env and fill in the required information.

#
# Printer Setup
#

# Printer Connection: usb or network
MARKY_TYPE=usb

# USB, get this information by running `lsusb` while your printer is connected. You should see something like this:
#
# Bus 001 Device 094: ID 04b8:0e20 Seiko Epson Corp. TM-m30-ii
MARKY_VENDOR_ID=0x04b8
MARKY_PRODUCT_ID=0x0e20

# Network, how you get this information depends on which printer you have.
MARKY_IP=192.168.1.100
MARKY_PORT=9100

#
# Configuration Setup
#

# Number of lines to print before truncating output to avoid printing out LOTR.
MARKY_MAX_LINES=30

# Max line width supported by the printer for text-wrapping.
MARKY_LINE_WIDTH=48

Running with Docker (Recommended)

Docker is the easiest way to get ThermalMarky up and running, especially for managing USB permissions.

Build and Start:

docker compose up --build

Access the UI: Open https://localhost:8000 in your browser. (Note: Uses self-signed certificates in certs/ for secure transport)

If you prefer to run it bare-metal, follow these steps:

  • Python 3.12+
  • System libraries (for python-escpos):
sudo apt install libusb-1.0-0-dev libjpeg-dev zlib1g-dev libcups2-dev python3-dev gcc

Install Dependencies:

python3 -m venv .venv
pip install -r requirements.txt
. .venv/bin/activate

Launch the Web Server:

You can print files directly without the web interface:

# Print a file
python print.py my_list.md

# Pipe content directly
echo "# Hello World" | python print.py

# HTTP request
curl --insecure -X POST "https://127.0.0.1:8000/print" -d "markdown=$(cat my-message.md)"
# or
curl --insecure -X POST "https://127.0.0.1:8000/print" --data-urlencode "[email protected]"

Beyond standard Markdown, ThermalMarky supports special tags:

Tag Description
**word** Bold
__word__ Underline
# H1
## H2
[align=center] Center-align the following text (also left, right)
[qr=https://...] Generate and print a QR code
[effect=line--] Print a horizontal line of dashes
[effect=line-*] Print a horizontal line of asterisks
[align=center]# Thermal Marky

This is **very important** but this __not so much__.

[align=right]This is on the right

[effect=line--]

[align=center][qr=https://github.com/sadreck/ThermalMarky]

Printer UI

Result

Printer Sample

  • USB Permissions: On Linux, you might need to add a udev rule or run with sudo if the printer isn't detected. Docker-compose handles this by running as privileged.
  • Certificates: The web server uses HTTPS. If your browser warns you about the certificate, it's because it's self-signed for local use.
联系我们 contact @ memedata.com