Skip to main content

Python library for Paperang P2 thermal printer (USB protocol)

Project description

paperang-p2-lib

PyPI - Version Python Versions CI License: MIT

Python library for Paperang P2 thermal printer (USB protocol).

Based on hurui200320/java-paperang-p2-usb protocol.

Features

  • USB connection to Paperang P2 printer
  • Text printing (CJK support via optional [cjk] extra)
  • Image printing with adjustable brightness/contrast/threshold
  • QR code generation and printing
  • Pickup code printing (large bold)
  • Print profiles (portrait, landscape, document, etc.)
  • Pattern test and heat density test
  • Status and battery reading

Installation

# Basic (Latin fonts only)
pip install paperang-p2-lib

# With QR code support
pip install paperang-p2-lib[qr]

# With CJK (Chinese/Japanese/Korean) text support
pip install paperang-p2-lib[cjk]

# All extras
pip install paperang-p2-lib[qr,cjk]

Usage

from paperang import PaperangP2

printer = PaperangP2()
printer.connect()

# Print text
printer.print_text("Hello World!", font_size=24)

# Print CJK text (requires [cjk] extra)
printer.print_text("你好世界", font_size=24)

# Print image
printer.print_image("photo.jpg", profile="portrait")

# Print QR code
printer.print_qr("https://example.com")

# Print pickup code
printer.print_pickup_code("19-4308")

# Get status
status = printer.get_status()
battery = printer.get_battery()

API Reference

PaperangP2 Class

Method Description
connect() Connect to printer via USB
print_text(text, font_size, heat_density) Print text (CJK requires [cjk] extra)
print_image(path, heat_density, feed_before, feed_after, threshold, brightness, contrast) Print image
print_qr(content, box_size, heat_density, max_width) Print QR code
print_pickup_code(code, heat_density) Print large bold pickup code
set_heat_density(density) Set heat density (0-100)
set_paper_type(paper_type) Set paper type (0=normal, 1=continuous)
feed(lines) Feed paper
print_test_page() Print test page
get_status() Get printer status
get_battery() Get battery level
print_pattern_test() Print pattern test
print_heat_density_test() Print heat density gradient

Utility Functions

  • crc32_paperang(data, seed) — Paperang-specific CRC32
  • pack_packet(cmd, data, packet_remain) — Pack protocol packet
  • load_profiles(profiles_path) — Load print profiles from JSON
  • list_profiles(profiles_path) — Print available profiles

Fonts

Font Size Package Purpose
DejaVuSans 742K ✅ Always included Latin text fallback
DejaVuSans-Bold 693K ✅ Always included Pickup codes (bold)
wqy-microhei 5.0M [cjk] extra CJK (Chinese/Japanese/Korean)

CJK Support

CJK text printing requires the optional [cjk] dependency:

pip install paperang-p2-lib[cjk]

This installs paperang-p2-fonts-cjk, which provides the 文泉驿微米黑 (WenQuanYi Micro Hei) font.

When [cjk] is installed, print_text() automatically uses the CJK font first, falling back to DejaVuSans for Latin characters. Without [cjk], CJK characters will render as boxes or missing glyph symbols.

Protocol Details

  • Vendor ID: 0x4348
  • Product ID: 0x5584
  • Print width: 576 pixels (72 bytes/line)
  • Packet size: 14 lines per packet (1008 bytes)

Packet Format

[0x02] [CMD:1B] [packetRemain:1B] [dataLength:2B LE] [DATA:0-1023B] [CRC32:4B LE] [0x03]

Key Commands

Command Description
0x00 Print bitmap data
0x0C Get status
0x10 Get battery level
0x19 Set heat density (0-100)
0x1A Feed paper
0x1B Print test page
0x2C Set paper type

CRC32

Custom seed 0x35769521 (standard CRC32 uses 0x00000000).

Related Projects

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

paperang_p2_lib-0.2.1.tar.gz (751.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

paperang_p2_lib-0.2.1-py3-none-any.whl (748.7 kB view details)

Uploaded Python 3

File details

Details for the file paperang_p2_lib-0.2.1.tar.gz.

File metadata

  • Download URL: paperang_p2_lib-0.2.1.tar.gz
  • Upload date:
  • Size: 751.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for paperang_p2_lib-0.2.1.tar.gz
Algorithm Hash digest
SHA256 be4b7e3133d6e58f5233d034853c797d29138760f1c8020e90f48ba683262bec
MD5 f5546bdaea806591ebe06d83072dbf9e
BLAKE2b-256 dab6ee750c127da42acd2c060feb927a6049ee4882228512bfc933ee78ba7a7f

See more details on using hashes here.

File details

Details for the file paperang_p2_lib-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: paperang_p2_lib-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 748.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for paperang_p2_lib-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 47bbf878d30a392de2017ddb9b2fd0b6e44d1e0af31feabcd414c298dc565c5d
MD5 ac50e28e17592a0d6b37c7790538d737
BLAKE2b-256 8f18223b222cfd14a793587e4520b6193a936b3dd48601be0cbdfb4f6840a43b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page