2016-08-01 10:24:07 +00:00
|
|
|
Printing Barcodes
|
|
|
|
-----------------
|
2023-08-08 22:52:01 +00:00
|
|
|
|
2023-08-09 23:38:47 +00:00
|
|
|
:Last Reviewed: 2023-08-10
|
2016-08-01 10:24:07 +00:00
|
|
|
|
2023-07-12 18:45:41 +00:00
|
|
|
Many printers implement barcode printing natively.
|
2023-08-09 23:38:47 +00:00
|
|
|
This hardware renderered barcodes are fast but the supported
|
|
|
|
formats are limited by the printer itself and different between models.
|
|
|
|
However, almost all printers support printing images, so barcode
|
|
|
|
rendering can be performed externally by software and then sent
|
|
|
|
to the printer as an image.
|
|
|
|
As a drawback, this operation is much slower and the user needs
|
|
|
|
to know and choose the image implementation method supported by
|
|
|
|
the printer's commandset.
|
2016-08-01 10:24:07 +00:00
|
|
|
|
|
|
|
barcode-method
|
|
|
|
~~~~~~~~~~~~~~
|
2023-08-09 23:38:47 +00:00
|
|
|
Since version 3.0, the ``barcode`` method unifies the previous
|
|
|
|
``barcode`` (hardware) and ``soft_barcode`` (software) methods.
|
|
|
|
It is able to choose automatically the best printer implementation
|
|
|
|
for barcode printing based on the capabilities of the printer
|
|
|
|
and the type of barcode desired.
|
|
|
|
To achieve this, it relies on the information contained in the
|
|
|
|
escpos-printer-db profiles.
|
|
|
|
The chosen profile needs to match the capabilities of the printer
|
|
|
|
as closely as possible.
|
2016-08-01 10:24:07 +00:00
|
|
|
|
|
|
|
.. py:currentmodule:: escpos.escpos
|
|
|
|
|
|
|
|
.. automethod:: Escpos.barcode
|
|
|
|
:noindex:
|
|
|
|
|
|
|
|
CODE128
|
|
|
|
~~~~~~~
|
|
|
|
Code128 barcodes need a certain format.
|
|
|
|
For now the user has to make sure that the payload is correct.
|
|
|
|
For alphanumeric CODE128 you have to preface your payload with `{B`.
|
|
|
|
|
|
|
|
.. code-block:: Python
|
|
|
|
|
|
|
|
from escpos.printer import Dummy, Serial
|
|
|
|
p = Serial()
|
|
|
|
# print CODE128 012ABCDabcd
|
|
|
|
p.barcode("{B012ABCDabcd", "CODE128", function_type="B")
|
|
|
|
|
2023-08-09 23:38:47 +00:00
|
|
|
A very good description on CODE128 is also on
|
|
|
|
`Wikipedia <https://en.wikipedia.org/wiki/Code_128>`_.
|