Skip to main content

Python library for Paperang P2 thermal printer (USB protocol)

Project description

paperang-p2-lib

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 (Latin fonts only)
pip install paperang-p2-lib

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

# With CJK font support (Chinese, Japanese, Korean)
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 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 🔲 [cjk] extra CJK (Chinese/Japanese/Korean)

Without [cjk], Chinese/Japanese/Korean text will fall back to the system font or default (may show squares).

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: paperang_p2_lib-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 4b77dc65970b9953ad3b01eb60581a0885d7357ed74f050126e774ea7fa0fc24
MD5 f1746e6eca4af8a42acac8e7718a11e2
BLAKE2b-256 83559a861a7e93929d14b6f0e02e900aa4e84896388a3b85c4a0497aa6988960

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for paperang_p2_lib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c58b44fca9ccb4f530c148a40d334fbd564261b8427787d53ee5d6b8ca30ba8
MD5 776ce36ef5865b4f80117aefcee17590
BLAKE2b-256 b3f3658c2413c27dacd102136c23691b0d81466f7a714ba659a65a13384294f7

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