Skip to main content

oneprint is a uniform print library. It use XML to define print data. Now it can convert XML to ESC/POS data or Pillow Image object.

Project description

oneprint

oneprint is a uniform print library. It use XML to define print data. Now it can convert XML to ESC/POS data or Pillow Image object.

Install Dependencies

 pip install requests qrcode pillow pystrich python-escpos

Install oneprint

 pip install oneprint

XML define syntax

<!-- define a paper -->
<xml width="384|576|...">
    <!-- show text -->
    <text align="left|right|center" font="A|B">Hello</text>
    <!-- show a horizontal line -->
    <hr char="-|*|+..."/>
    <!--  show image  -->
    <img align="left|right|center" src="https://xxx"/>
    <!--  show QRCode  -->
    <qrcode native="false|true" align="left|right|center">Hello</qrcode>
    <!--  show barcode  -->
    <barcode align="left|right|center" type="code128|ean13">123456789012</barcode>

    <!--  show table  -->
    <table border="1|2|3...">
        <tr border="1|2|3...">
            <td align="center" colspan="1|2|3..." width="1|2|3...">Time</td>
            <td align="center" width="1|2|3...">Content</td>
            <td align="center" width="1|2|3...">Remark</td>
        </tr>
    </table>
</xml>

XML define demo

<xml>
    <!-- text -->
    <text align="center">oneprint is a uniform print library, support ESC/POS printer.</text>
    <!-- table -->
    <hr/>
    <text/>
    <table>
        <tr>
            <td align="left">日期:2021-04-28</td>
            <td align="right">编号:0001</td>
        </tr>
    </table>
    <text/>
    <table border="1">
        <tr border="1">
            <th colspan="3" align="center" width="8">Title</th>
        </tr>
        <tr border="1">
            <th align="center" width="8">Time</th>
            <th align="center" width="20">Content</th>
            <th align="center" width="20">Remark</th>
        </tr>
        <tr border="1">
            <td>18:00</td>
            <td>This is content field! Just test!</td>
            <td align="center">Empty</td>
        </tr>
        <tr border="1">
            <td>19:00</td>
            <td colspan="2">Content 2</td>
        </tr>
    </table>
    <text>A Image</text>
    <!-- image -->
    <img align="center" src="https://img3.doubanio.com/dae/accounts/resources/527f922/sns/assets/lg_main@2x.png"/>
    <text>A Qrcode</text>
    <!-- qrcode -->
    <qrcode align="center">Hello</qrcode>
    <text>A Barcode</text>
    <!-- ean13 barcode -->
    <barcode align="center" type="ean13">123456789012</barcode>
    <!-- cur the page -->
    <cut/>
</xml>

The result:

all

Usage

# print to a image and show
data = '''
<text>Hello World</text>
<qrcode>Hello World</qrcode>
'''
from oneprint import ImageDrawPrint
pt = ImageDrawPrint()
pt.auto_print(data)
pt.show() # use Pillow Image.show()
# save to file
pt.get_image().save('/tmp/tt.jpeg')

# or print with python-escpos
from oneprint import EscPosPrint
ep = EscPosPrint()
ep.auto_print(data)

from escpos.printer import Serial
p = Serial(devfile='/dev/tty.usbserial',
           baudrate=9600,
           bytesize=8,
           parity='N',
           stopbits=1,
           timeout=1.00,
           dsrdtr=True)
p._raw(ep.get_data())

The result:

t2

Click to view more information!

CHANGES

1.0.0

  • first version

1.0.6

  • support <hr/> in table

1.2.0

  • support align attribute in <text> node with ImageDrawPrint

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

oneprint-1.2.6.tar.gz (7.9 kB view details)

Uploaded Source

File details

Details for the file oneprint-1.2.6.tar.gz.

File metadata

  • Download URL: oneprint-1.2.6.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.16

File hashes

Hashes for oneprint-1.2.6.tar.gz
Algorithm Hash digest
SHA256 006ded7cc41d9364212a4a1859daaba28b026f67f83e69a950956db79ec71f52
MD5 1c7caba7ab03cf3cc81715ffb3022a7f
BLAKE2b-256 ad65eda40e768cebd039ee2c531e7848ddc05b9d5fdd4a911f21e862ddb23b26

See more details on using hashes here.

Supported by

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