Example #1
0
def createBarCodes():
    """
    Create barcode examples and embed in a PDF
    """
    c = canvas.Canvas("barcodes.pdf", pagesize=A4)

    barcode_value = "1234567890"

    barcode39 = code39.Extended39(barcode_value)
    barcode39Std = code39.Standard39(barcode_value, barHeight=20, stop=1)

    # code93 also has an Extended and MultiWidth version
    barcode93 = code93.Standard93(barcode_value)

    barcode128 = code128.Code128(barcode_value)
    # the multiwidth barcode appears to be broken
    #barcode128Multi = code128.MultiWidthBarcode(barcode_value)

    barcode_usps = usps.POSTNET("50158-9999")

    codes = [barcode39, barcode39Std, barcode93, barcode128, barcode_usps]

    x = 1 * mm
    y = 285 * mm
    x1 = 6.4 * mm

    for code in codes:
        code.drawOn(c, x, y)
        y = y - 15 * mm

    # draw the eanbc8 code
    barcode_eanbc8 = eanbc.Ean8BarcodeWidget(barcode_value)
    bounds = barcode_eanbc8.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(50, 10)
    d.add(barcode_eanbc8)
    renderPDF.draw(d, c, 15, 555)

    # draw the eanbc13 code
    barcode_eanbc13 = eanbc.Ean13BarcodeWidget(barcode_value)
    bounds = barcode_eanbc13.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(50, 10)
    d.add(barcode_eanbc13)
    renderPDF.draw(d, c, 15, 465)

    # draw a QR code
    qr_code = qr.QrCodeWidget(
        'https://stackoverflow.com/questions/10147455/how-to-send-an-email-with-gmail-as-provider-using-python'
    )
    bounds = qr_code.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(45, 45, transform=[45. / width, 0, 0, 45. / height, 0, 0])
    d.add(qr_code)
    renderPDF.draw(d, c, 15, 405)

    c.save()
Example #2
0
def createBarCodes():
    """
    Create barcode examples and embed in a PDF
    """
    c = canvas.Canvas("barcodes.pdf", pagesize=letter)

    barcode_value = "12345678999M"

    barcode39 = code39.Extended39(barcode_value)
    barcode39Std = code39.Standard39(barcode_value, barHeight=20, stop=1)

    # code93 also has an Extended and MultiWidth version
    barcode93 = code93.Standard93(barcode_value)

    barcode128 = code128.Code128(barcode_value)
    # the multiwidth barcode appears to be broken
    #barcode128Multi = code128.MultiWidthBarcode(barcode_value)

    barcode_usps = usps.POSTNET("50158-9999")

    codes = [barcode39, barcode39Std, barcode93, barcode128, barcode_usps]

    x = 1 * mm
    y = 260 * mm
    x1 = 6.4 * mm

    for code in codes:
        code.drawOn(c, x, y)
        y = y - 30 * mm
    barcode_value = "123456789990"

    # draw the eanbc8 code
    barcode_eanbc8 = eanbc.Ean8BarcodeWidget(barcode_value)
    bounds = barcode_eanbc8.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(50, 10)
    d.add(barcode_eanbc8)
    renderPDF.draw(d, c, 150 * mm, 150 * mm)

    # # draw the eanbc13 code
    barcode_eanbc13 = eanbc.Ean13BarcodeWidget(barcode_value)
    bounds = barcode_eanbc13.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(50, 10)
    d.add(barcode_eanbc13)
    renderPDF.draw(d, c, 150 * mm, 100 * mm)

    # # draw a QR code
    qr_code = qr.QrCodeWidget('www.ghf.com')
    bounds = qr_code.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(45, 45, transform=[45. / width, 0, 0, 45. / height, 0, 0])
    d.add(qr_code)
    renderPDF.draw(d, c, 150 * mm, 50 * mm)

    c.save()
Example #3
0
    def generate_barcode_and_text(self, text, value, y_text):
        barcode_eanbc8 = eanbc.Ean8BarcodeWidget(value,
                                                 width=22 * mm,
                                                 height=12 * mm,
                                                 barHeight=8 * mm,
                                                 fontSize=5)
        bounds = barcode_eanbc8.getBounds()
        width = bounds[2] - bounds[0]
        height = bounds[3] - bounds[1]
        d = Drawing(width, height)
        d.add(barcode_eanbc8)

        title = self.generate_centered_text(text, y_text, 4)
        disclaimer = self.generate_centered_text("Mindkeepr", y_text - 10, 3)
        return d, title, disclaimer
def eanbc_demo(barcode_value):
    c = canvas.Canvas('eanbc_demo.pdf')

    barcode_eanbc8 = eanbc.Ean8BarcodeWidget(barcode_value)
    bounds = barcode_eanbc8.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(50, 10)
    d.add(barcode_eanbc8)
    renderPDF.draw(d, c, 15, 555)

    # draw the eanbc13 code
    barcode_eanbc13 = eanbc.Ean13BarcodeWidget(barcode_value)
    bounds = barcode_eanbc13.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(50, 10)
    d.add(barcode_eanbc13)
    renderPDF.draw(d, c, 15, 465)
    c.save()
Example #5
0
    def createBarCodes(c):
        barcode_value = '0112358'

        barcode39 = code39.Extended39(barcode_value)
        barcode39Std = code39.Standard39(barcode_value, barHeight=20, stop=1)

        barcode93 = code93.Standard93(barcode_value)

        barcode128 = code128.Code128(barcode_value)
        # barcode128Multi = code128.MultiWidthBarcode(barcode_value)

        barcode_usps = usps.POSTNET('50158-9999')

        codes = [barcode39, barcode39Std, barcode93, barcode128, barcode_usps]

        x = 1 * mm
        y = 285 * mm

        for code in codes:
            code.drawOn(c, x, y)
            y = y - 15 * mm

        barcode_eanbc8 = eanbc.Ean8BarcodeWidget(barcode_value)
        d = Drawing(50, 10)
        d.add(barcode_eanbc8)
        renderPDF.draw(d, c, 15, 555)

        barcode_eanbc13 = eanbc.Ean13BarcodeWidget(barcode_value)
        d = Drawing(50, 10)
        d.add(barcode_eanbc13)
        renderPDF.draw(d, c, 15, 465)

        qr_code = qr.QrCodeWidget('http://www.baidu.com')
        bounds = qr_code.getBounds()
        width = bounds[2] - bounds[0]
        height = bounds[3] - bounds[1]
        d = Drawing(45, 45, transform=[45./width, 0,0,45./height, 0, 0])
        d.add(qr_code)
        renderPDF.draw(d, c, 15, 405)
def createBarCodes():
    """
    Create barcode examples and embed in a PDF

    """
    #Taking the filename from the user
    name = input('enter a filename(.pdf) :')

    c = canvas.Canvas(name, pagesize=letter)

    #Setting the 10 digit barcode value
    barcode_value = str(random_with_N_digits(12))

    barcode39 = code39.Extended39(barcode_value)
    barcode39Std = code39.Standard39(barcode_value, barHeight=20, stop=1)

    # code93 also has an Extended and MultiWidth version
    barcode93 = code93.Standard93(barcode_value)

    barcode128 = code128.Code128(barcode_value)
    # the multiwidth barcode appears to be broken
    #barcode128Multi = code128.MultiWidthBarcode(barcode_value)

    codes = [barcode39, barcode39Std, barcode93, barcode128]

    x = 1 * mm
    y = 285 * mm
    x1 = 6.4 * mm

    for code in codes:
        code.drawOn(c, x, y)
        y = y - 15 * mm

    # draw the eanbc8 code
    barcode_eanbc8 = eanbc.Ean8BarcodeWidget(barcode_value)
    bounds = barcode_eanbc8.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(50, 10)
    d.add(barcode_eanbc8)
    renderPDF.draw(d, c, 15, 555)

    # draw the eanbc13 code
    barcode_eanbc13 = eanbc.Ean13BarcodeWidget(barcode_value)
    bounds = barcode_eanbc13.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(50, 10)
    d.add(barcode_eanbc13)
    renderPDF.draw(d, c, 15, 465)

    # draw a QR code
    qr_code = qr.QrCodeWidget(barcode_value)
    bounds = qr_code.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(45, 45, transform=[45. / width, 0, 0, 45. / height, 0, 0])
    d.add(qr_code)
    renderPDF.draw(d, c, 15, 405)

    c.save()