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 with 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
pip install paperang-p2-lib

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

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

Usage

from paperang import PaperangP2

printer = PaperangP2()
printer.connect()

# Print text
printer.print_text("Hello World!", 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 Included Purpose
DejaVuSans 742K ✅ Always Latin text fallback
DejaVuSans-Bold 693K ✅ Always Pickup codes (bold)
wqy-microhei 5.0M ✅ Always CJK (Chinese/Japanese/Korean)

CJK text is supported out of the box with the bundled wqy-microhei font.

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.1.1.tar.gz (3.1 MB 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.1.1-py3-none-any.whl (3.1 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: paperang_p2_lib-0.1.1.tar.gz
  • Upload date:
  • Size: 3.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for paperang_p2_lib-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7387e8349fe72578ba0ea72515375d5bfbfb34e82392240bf8ac2f8bcfeace1e
MD5 9bbb4aad1a1da8df3dd4b1018df97398
BLAKE2b-256 e81a2c4e44a08df12f0f791837d96a4b25fe8b986d3a75e7dd2e90ba6bfb54c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for paperang_p2_lib-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bc83a6470e8d5b9d23d61fb0a9bb55d15d88e471a9288dc1687372f3bfd27276
MD5 e94b623d120ab652b599a9985a428e9c
BLAKE2b-256 4a81d445b7273b96b917ee220cde78d3051540fd660b6ab4d9adc9fb44dc8cfb

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