Skip to main content

escpos-xml

escpos-xml is a library to parse XML defined receipt and print it on ESC/POS Printer using python-escpos library.

The module contains a RELAX NG schema for the XML: escpos_xml/escpos.rng. The syntax is quite similar to HTML.

Example:

>>> import os
>>> from io import BytesIO, open
>>> from escpos.printer import Usb
>>> from escpos_xml import parse
>>> xml = BytesIO('''
... <receipt width="48">
...     <h1>Receipt!</h1>
...     <ul>
...         <li>
...             <span align="left" width="22">Product</span>
...             <span align="right" width="24">0.15€</span>
...         </li>
...     </ul>
...     <hr/>
...     <p size="2h">
...         <span align="left" width="24">TOTAL</span>
...         <span align="right" width="24">0.15€</span>
...     </p>
...     <barcode encoding='ean13'>
...         5449000000996
...     </barcode>
...     <cashdraw pin="2"/>
...     <cut/>
... </receipt>''')
>>> printer = Usb(0x0483, 0x5743)
>>> parse(printer, xml)
>>> parse(printer,
...      open(os.path.join('escpos_xml', 'tests', 'image.xml'), 'rb'))

Documenation:

Root

The root element is receipt with the optional attribute width which is the number of character in a line.

In-lines:

The tags for in-line elements are: bold, b and span. The attribute available are: bold, underline, size, font, inverted and color. The span element can have also the attributes align and width.

Blocks:

The tags for block element are: p, h(1-5) and hr. The attributes are the same as the in-line elements with in addition the align which could be left, right or center.

Lists:

It is possible to have ordered or unordered lists with the elements ol and ul. The type of bullet is defined by the attribute type. For ordered list, the start number can be specify with the start attribute. Each item is defined by an element li which has the same attributes as the in-line elements.

The list can be nested.

Barcode:

The barcode element print the code using the encoding attribute as format. Other attributes are: width, height, position and font.

Image:

The img element print the image defined by the src attribute using a base64 data-url format. Example:

<img src="data:image/png;base64,AAABAAMAEBAAAAEAIABoBAAANgAAAC..."/>

Operations:

Some operations are available: cut, partialcut and cashdraw. The cashdraw element requires a pin attribute.

Release files for python-escpos-xml 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-escpos-xml 0.1.0
File Size Uploaded
python-escpos-xml-0.1.0.tar.gz 28.0 kB Details

Release files / python-escpos-xml-0.1.0.tar.gz

Download URL python-escpos-xml-0.1.0.tar.gz
Size 28.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c3c171c2a1b0a6a3ce87460262494e24d252b87742179e18d32971c88c913f4c
BLAKE2b-256 checksum
How to use checksums
45aefb081c18fd7447df5229edcf2ae9b8143edb37c363d3be04ee59cbec5f4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page