Using python3 and reportlab I'm trying to generate two columns of barcodes:
from reportlab.graphics.barcode import code39
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import mm
from reportlab.pdfgen import canvas
c = canvas.Canvas("barcode_example.pdf", pagesize=A4)
code_list = [
'E100', 'RA100',
'E101', 'RA101',
'E102', 'RA102',
'E103', 'RA103',
'E104', 'RA104',
'E105', 'RA105',
'E106', 'RA106',
'E107', 'RA107',
'E108', 'RA108',
'E109', 'RA109']
x = 1 * mm
y = 278 * mm
x1 = 6.4 * mm
for i, code in enumerate(code_list):
barcode = code39.Extended39(code, barWidth=0.6*mm, barHeight=15*mm)
if i % 2 == 0:
barcode.drawOn(c, x, y)
x1 = x + 6.4 * mm
c.drawString(x1, y- 5 * mm, code)
else:
x1 = x + 100 * mm
barcode.drawOn(c, x1, y)
y = y - 5 * mm
c.drawString(x1 + 6.4 * mm, y, code)
y = y - 25 * mm
# if int(y) == 0:
# x = x + 50 * mm
# y = 285 * mm
c.showPage()
c.save()
It generates a file and seems to be just fine but after scanning them in with a barcode scanner they read as follows:
E100F RA100
E101G RA101$
E102H RA102/
E103I RA103+
E104J RA104%
E105K RA1050
E106L RA1061
E107M RA1072
E108N RA1083
E109O RA1094
RA100 has a space after it. It is clearly going in order of ASCII precedence I just don't know why. Is there a setting I'm suppose to enable/disable?
Also, it's definitely not the barcode scanner, I reset it to read code39 and tested it on other non-reportlab generated barcodes and they worked just fine.
Thank you for your help!
Also, I modified the code from here: https://stackoverflow.com/questions/2179269/python-barcode-generation-library
Edit When I tested with code128, it worked perfectly. So it appears to be specific to code39
EDIT 2: And I'm an idiot. My barcode scanner doesn't support the checksum option. Disabling the checksum in reportlab fixed my issue. I'm going to leave this just in case someone else comes across this problem.
Disable checksum via:
barcode = code39.Extended39(code, barWidth=0.6*mm, barHeight=15*mm, checksum=0)
checksum=False would probably work just fine, but after looking at their source they use 1 and 0 for true/false and figured it would be safer to adhere to their practices.