Exemplo n.º 1
0
def crear_barcode(numero):
	filename = os.path.join('generated','temp',str(numero))
	print filename
	writer = barcode.writer.ImageWriter()
	code = barcode.Code39(numero,writer = writer,add_checksum = False)
	archivo = code.save(filename)
	return archivo
Exemplo n.º 2
0
def show_barcode(request, text):
    """Return text as a barcode."""
    if request.GET.get('f') == 'svg':
        import barcode
        output = StringIO.StringIO()
        code = barcode.Code39(text, add_checksum=False)
        code.write(output)
        contents = output.getvalue()
        output.close()
        return HttpResponse(contents, content_type="image/svg+xml")

    d = BarcodeDrawing(text)
    return HttpResponse(d.asString("png"), content_type="image/png")
Exemplo n.º 3
0
	def makeBarcodes(self, progress):
		"""Generate an HTML table which links to all the locations as barcode images."""
		import xml.etree.ElementTree as et
		from xml.dom import minidom

		# We must build all the mark-up around our table of images.
		html = et.Element("html")
		head = et.SubElement(html, "head")
		title = et.SubElement(head, "title")
		title.text = "Barcode Labels for {0}".format(self[0].building)
		style = et.SubElement(head, "style", {"type": "text/css"})
		# Make the table cells fit on 4X2 labels with a snippet of stylesheet.
		style.text = """
			td img {
			  width: 3.5in;
			  height: 1.75in;
			  text-align: center;
			  vertical-align: center;
			}
		"""
		body = et.SubElement(html, "body")
		h1 = et.SubElement(body, "h1")
		h1.text = title.text
		table = et.SubElement(body, "table")
		i = 0
		for label in self:
			# Generate the barcode.Code39 object.
			code = barcode.Code39(str(label), add_checksum=False)
			# All images will be generated in a barcodes directory under the
			# working directory.
			fileName = os.path.join("barcodes", str(label))
			# We'll only write the images to disk if they don't already exist.
			if not os.path.exists(fileName + ".svg"):
				# Save the image as an svg file with large print.
				code.save(fileName, {"font_size": 16})
			# Limit the table width to self.columns.
			if i % self.columns == 0:
				tr = et.SubElement(table, "tr")
			td = et.SubElement(tr, "td")
			# We pass a dictionary when creating the image specifying the src and alt
			# attributes.
			img = et.SubElement(td, "img",
				{"src": os.path.altsep.join(os.path.split(fileName + ".svg")),
				"alt": str(label)
			})
			# Mustn't forget to increment the counter for the columnizing.
			i += 1
			progress.Update(i)
			progress.Show()
		# Return a pretty printed version of the html.
		return minidom.parseString(et.tostring(html)).toprettyxml(indent="  ")
Exemplo n.º 4
0
def code39(text, size, dpi=300):
    """Create a barcode image given text and size box."""
    writer = ImageWriter()
    options = dict(write_text=False, writer=writer, dpi=int(dpi), quiet_zone=0)

    def px2mm(px):  # pylint: disable=invalid-name
        """Convert pixels to millimeters for our given DPI."""
        return 25.4 * px / options["dpi"]

    code = barcode.Code39(str(text), writer=writer, add_checksum=False)

    raw = code.build()
    modules_per_line = len(raw[0])
    module_width = px2mm(size[0]) / modules_per_line
    options["module_width"] = module_width

    module_height = px2mm(size[1]) - 2  # barcode adds this for some reason
    options["module_height"] = module_height

    return code.render(options)
Exemplo n.º 5
0
 def crear_code39(self, valor, archivo):
     code39 = barcode.Code39(valor, writer=barcode.writer.ImageWriter())
     filename = code39.save(archivo)
Exemplo n.º 6
0
def generate(cod):
    EAN = barcode.Code39(cod, add_checksum=False)
    EAN.save(getcwd() + "/temp/%s" % cod, options={'module_height': 7.0})
Exemplo n.º 7
0
def generate_barcode(member_id):
    """Returns a string representing an SVG element of a Code 39 Barcode of the provided member ID."""
    return barcode.Code39(member_id.zfill(8)).render(writer_options={},
                                                     text="").decode('utf-8')
Exemplo n.º 8
0
import random, string, barcode, os  # import the necessary modules


def newID():  # function to make 11 character random alphanumeric IDs
    x = ''.join(
        random.choice(string.ascii_letters.upper() + string.digits)
        for _ in range(11))
    # generate a random uppercase letter or number and append it to a string 11 times
    return x  # return string


ID = ""
while len(ID) != 11 or ID.isalnum() is False:
    ID = input("Enter barcode to generate, or leave blank for random:")
    if ID == '':
        ID = newID()  # generate ID
        break
    elif len(ID) != 11 or ID.isalnum() is False:
        print("Invalid ID")
bc = barcode.Code39(
    ID.upper())  # create a code39 barcode with a checksum for the ID
name = bc.save(
    'barcode'
)  # save it under the name "barcode.svg", overwrite existing file with this name
os.startfile("barcode.svg")  # open the file