【发布时间】:2020-01-22 09:04:21
【问题描述】:
我正在尝试在我的应用中为每个项目创建条形码
代码如下:
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'))
如何将每个文件保存在桌面位置,即r'C:\Users\Rahul\Desktop',文件名为 SKU 名称?
【问题讨论】:
-
@RamonMedeiros 抱歉,没有。我想将条形码存储在本地计算机上,而不是 S3 上
-
请添加适当的标签并编辑标题。现在太宽泛了。
-
是的,但显示了如何保存:
barcode.save(formats=['gif','pdf'],outDir=path_to_save,fnRoot=filename)
标签: python python-3.x