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.0.tar.gz (750.1 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.0-py3-none-any.whl (746.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: paperang_p2_lib-0.2.0.tar.gz
  • Upload date:
  • Size: 750.1 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.0.tar.gz
Algorithm Hash digest
SHA256 c2d2bb553b93135183816ef26584ff2751ce038177c36419fc04052ab8c2ad65
MD5 aa694e3fdc563ead81683ba6537e3ee3
BLAKE2b-256 fbbc588acac296760923e523bf295975e215af931a17b822a5f36edb7278dc2d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for paperang_p2_lib-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6fd60bc5be9196c8c76cc8b933ed8d4c3dbfafef1d692c2326fc68b033f9ca1e
MD5 330a45f18436f9abbaa89e30c24e950b
BLAKE2b-256 4f16ddaf7836e16dd5f4a095b1415149815f8f2adb1bc947dbc9adac0c932224

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