user3445881
user3445881

Reputation: 71

How to stop ReportLab appending unwanted character to barcode?

I create a pdf-page with barcodes on it using ReportLab. Everything works except that when I scan one of the barcodes it appends a character. For example when I try to scan 700124 I get 700124A, 700224 becomes 700224B, etc. I do not want these characters to be appended. Does anyone know how to stop this? I could not find any documentation about this. I use the following Python code:

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 = ['700124', '700224', '700324', '700424', '700524', '700624', '700724', '700824', '700924']

x = 1 * mm
y = 280 * mm
x1 = 6.4 * mm
r = 0

for code in code_list:
    barcode = code39.Standard39(code, barHeight=26, stop=1)
    barcode.drawOn(c, x, y)
    x1 = x + 6.4 * mm
    y = y - 5 * mm
    c.drawString(x1, y, code)
    x = x
    y = y - 25 * mm

    if int(y) < 0:
        if r != 3:
            x = x + 50 * mm
            y = 280 * mm
            r = r + 1
        else:
            c.showPage()
            x = 1 * mm
            y = 280 * mm
            x1 = 6.4 * mm
            r = 0

c.save()

Upvotes: 2

Views: 1586

Answers (1)

Eric
Eric

Reputation: 71

Even though the user claims it's not being added, by default the reportlab barcode library automatically adds the checksum.

To avoid the checksum character, initialize your barcode with the parameter checksum=0, like so:

barcode = code39.Standard39(code, barHeight=26, stop=1, checksum=0)

Upvotes: 3

Related Questions