Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Barcode not printed #609

Open
tuxmaster5000 opened this issue Dec 11, 2023 · 4 comments
Open

Barcode not printed #609

tuxmaster5000 opened this issue Dec 11, 2023 · 4 comments

Comments

@tuxmaster5000
Copy link

I have:

  • [X ] searched open and closed issues for duplicates

Bug description

When I try to print barcode on the printer only an error will shown on the console.

Error message:

Using bitImageColumn software barcode renderer
Traceback (most recent call last):
  File "/home/<XX>/test2.py", line 27, in <module>
    p.barcode("12345678", "EAN8")
  File "/home/<XX>/lib64/python3.11/site-packages/escpos/escpos.py", line 599, in barcode
    self._sw_barcode(
  File "/home/<XX>/lib64/python3.11/site-packages/escpos/escpos.py", line 858, in _sw_barcode
    self.image(image, impl=impl, center=center)
  File "/home/<XX>/lib64/python3.11/site-packages/escpos/escpos.py", line 222, in image
    raise ImageWidthError("{} > {}".format(im.width, max_width))
escpos.exceptions.ImageWidthError: Image width is too large (201 > 200)

Steps to reproduce

code:

import escpos.printer
p = escpos.printer.File("/dev/usb/lp0", profile="TM-U220B")
# While the profile is buggy
p.profile.profile_data["media"]["width"]["pixels"] = 200
p.textln("EAN8")
# as far I know it will only fits vertical on the paper 
p.set(flip=True)
p.barcode("12345678", "EAN8")
p.set(flip=False)
p.textln("EAN13")
p.set(flip=True)
p.barcode("1234567890123", "EAN13")
p.cut()

Printer: Epson TM-U220B

python-escpos version: 3.1.dev6+g5914c7c

python version: 3.11.6

operating system: Fedora-38

@belono
Copy link
Contributor

belono commented Dec 11, 2023

Hi @tuxmaster5000 !

Add the width=2 parameter to the barcode() method to reduce the module width of the rendered barcode to the minimum size:

p.barcode("12345678", "EAN8", width=2)

Note that, due to your printer having a low resolution, some long barcode types will not fit into the paper raising the former exception.

@tuxmaster5000
Copy link
Author

Which the width=2 option, the printer starts printing, but only garbage output.
Pol1

@belono
Copy link
Contributor

belono commented Dec 12, 2023

Yeah, this is the same as in #598 . The printer does not support native hardware bar-code printing so the library automatically switches to software bar-code to render an image of the bar-code and relies on the image() method to print the image (bar-code). Again, the default values of the image() method are incompatible with the TM-U2xx series, so the printer ends up printing garbage.

We could workaround the barcode() method too to allow passing custom parameters to the image() method through its force_software parameter, taking care if possible of not break the current behavior of force_software which selects the best render mode based in the printer capabilities profile data.
However, if it is not too urgent for @tuxmaster5000 to have bar-code working I think it would be easier to add a field in the capabilities database and fix all this issues at a time.

@tuxmaster5000
Copy link
Author

Hi @belono it will not be so urgent, because after fixed the qr part, this was an try if this also works.
I need more the qr code function, so waiting will not be an problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants