Ich mag eine Rechnung im PDF-Format mit Barcode erstellen, erste mybarcode.py Datei reportlabwie eine Rechnung im PDF mit Barcode in django erstellen
# mybarcode.py-Datei erstellen Barcode mit barecode erstellen
from reportlab.lib.units import mm
from reportlab.graphics.barcode import createBarcodeDrawing
from reportlab.graphics.shapes import Drawing, String
from reportlab.graphics.charts.barcharts import HorizontalBarChart
class MyBarcodeDrawing(Drawing):
def __init__(self, text_value, *args, **kw):
barcode = createBarcodeDrawing('Code128', value=text_value, barHeight=19*mm, humanReadable=True)
Drawing.__init__(self,barcode.width,barcode.height,*args,**kw)
self.add(barcode, name='barcode')
Ansichten Funktion zum Erstellen von PDF mit Barcode.
# views.py
from reportlab.platypus import SimpleDocTemplate
from reportlab.platypus.tables import Table
cm = 2.54
def print_pdf(request):
import mybarcode
product = Product.objects.get(id = id)
d = mybarcode.MyBarcodeDrawing(product.code)
binaryStuff = d.asString('jpg')
response = HttpResponse(content_type='application/pdf')
filename=somefilename.pdf'
elements = []
doc = SimpleDocTemplate(response, rightMargin=0, leftMargin=6.5 * cm, topMargin=0.3 * cm, bottomMargin=0)
data=[("barcode", binaryStuff),("name", "some_name")]
table = Table(data)
elements.append(table)
doc.build(elements)
return response
und immer diese Fehlermeldung: ungültiger Start-Byte