I am trying to create barcodes in my app for each of the items
Here's the code:
from base64 import b64encode
from reportlab.lib import units
from reportlab.graphics import renderPM
from reportlab.graphics.barcode import createBarcodeDrawing
from reportlab.graphics.shapes import Drawing
def get_barcode(value, width, barWidth = 0.05 * units.inch, fontSize = 30):
barcode = createBarcodeDrawing('Code128', value = value, barWidth = barWidth, fontSize = fontSize)
drawing_width = width
barcode_scale = drawing_width / barcode.width
drawing_height = barcode.height * barcode_scale
drawing = Drawing(drawing_width, drawing_height)
drawing.scale(barcode_scale, barcode_scale)
drawing.add(barcode, name='barcode')
return drawing
sku = ['A100', 'A101', 'A102', 'A103', 'A104', 'A105', 'A106', 'A107', 'A108', 'A109']
for i in sku:
barcode = get_barcode(value = i, width = 600)
data = b64encode(renderPM.drawToString(barcode, fmt = 'PNG'))
How can I save every file at the desktop location i.e. r'C:\Users\Rahul\Desktop'
with the filename as SKU Name ?