示例#1
0
    def get_grf(png, rotate):
        u"""Get a GRF from a png.

        params:
            png: BytesIO stream
            rotate: rotate 90° if true
        """
        if rotate:
            png_bytes = BytesIO()
            (Image.open(png).rotate(90, expand=True).save(png_bytes, format="PNG"))
            png = png_bytes.getvalue()
            png_bytes.close()

        return GRF.from_image(png, "DEMO")
示例#2
0
    def get_grf(png, rotate):
        u"""Get a GRF from a png.

        params:
            png: BytesIO stream
            rotate: rotate 90° if true
        """
        if rotate:
            png_bytes = BytesIO()
            (Image
                .open(png)
                .rotate(90, expand=True)
                .save(png_bytes, format="PNG"))
            png = png_bytes.getvalue()
            png_bytes.close()

        return GRF.from_image(png, 'DEMO')
示例#3
0
    def print(weight, public_price, price_pakke):
        try:

            client = pdfcrowd.HtmlToImageClient(
                'JosepRoo', 'd508735c4b86f87fd4a3961d5195126b')

            # configure the conversion
            client.setOutputFormat('png')

            # run the conversion and store the result into an image variable
            image = client.convertString(
                set_html(weight, public_price, price_pakke))
            temp_buff = BytesIO()
            temp_buff.write(image)
            # need to jump back to the beginning before handing it off to PIL
            temp_buff.seek(0)
            image = Image.open(temp_buff)
            # image = image.resize([720, 1080]) next resolution
            image = image.resize([830, 1133])
            temp_buff.seek(0)
            image.save(temp_buff, format='PNG')
            grf = GRF.from_image(temp_buff.getvalue(), 'ZPL')
            grf.optimise_barcodes()
            import socket
            mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            host = "169.254.239.30"
            port = 6101
            print(grf.to_zpl(compression=3, quantity=1))
            try:
                mysocket.connect((host, port))  # connecting to host
                mysocket.send(
                    bytes(grf.to_zpl(compression=3, quantity=1),
                          "utf-8"))  # using bytes
                mysocket.close()  # closing connection
            except:
                print("Error with the connection")
            # Some random options

        except pdfcrowd.Error as why:
            # report the error
            sys.stderr.write('Pdfcrowd Error: {}\n'.format(why))

            # handle the exception here or rethrow and handle it at a higher level
            raise
示例#4
0
文件: main.py 项目: jvjc/zebra-zpl
def main(prefix="*:", rows=1, cols=3):
    # Se crea la conexión con cups
    conn = cups.Connection()

    # Se obtiene el nombre de la impresora a usar
    printer_name = args.printer_name

    # Archivo temporal a enviar como raw
    label_file_path = "/tmp/label.zpl"

    # Se revisar si existe la impresora, en caso contrario se despliegan las disponibles
    if printer_name != "None":
        printers = conn.getPrinters()
        if printer_name not in printers.keys():
            print("printer not found\n\navailable printer:")
            print("\n".join(printers.keys()))
            return False

    # Comenzamos el archivo zql vacío
    global_zpl = ""

    for idx in range(int(rows)):
        # Se verifica cuantas columnas se ingresó para crear el tamaño del qr
        if cols == 3:
            qr_size = 2
        else:
            qr_size = 4

        # Se obtiene el qr izquiedo
        grf_left = GRF.from_image(generate_qr(prefix, qr_size),
                                  "L" + str(idx)[:7])
        grf_left.optimise_barcodes()
        qr_left = grf_left.to_zpl_line(compression=3, quantity=1)

        # Se obtiene el qr derecho
        grf_right = GRF.from_image(generate_qr(prefix, qr_size),
                                   "R" + str(idx)[:7])
        grf_right.optimise_barcodes()
        qr_right = grf_right.to_zpl_line(compression=3, quantity=1)

        # Si es de 3 columnas, entonces es el qr pequeño
        if cols == 3:
            # Se crea un qr central
            grf_center = GRF.from_image(generate_qr(prefix, qr_size),
                                        "C" + str(idx)[:7])
            grf_center.optimise_barcodes()
            qr_center = grf_center.to_zpl_line(compression=3, quantity=1)

            # Se posicionan los qr en la fila en diferente x
            zpl = [
                qr_left, qr_right, qr_center, "^XA", "^LH32,8",
                "^XGR:L" + str(idx)[:7] + ".GRF,1,1", "^FS", "^LH172,8",
                "^XGR:C" + str(idx)[:7] + ".GRF,1,1", "^FS", "^LH312,8",
                "^XGR:R" + str(idx)[:7] + ".GRF,1,1", "^FS", "^XZ"
            ]
        else:  # Si es de 2 columnas es el qr super y sólo necesita 2, es el default
            zpl = [
                qr_left, qr_right, "^XA", "^LH0,20",
                "^XGR:L" + str(idx)[:7] + ".GRF,1,1", "^FS", "^LH214,20",
                "^XGR:R" + str(idx)[:7] + ".GRF,1,1", "^FS", "^XZ"
            ]

        global_zpl = global_zpl + "\n".join(zpl) + "\n"

    # Si viene la etiqueta no-print entonces se regresa el archivo zpl
    if printer_name == "None":
        print(global_zpl)
    else:
        f = open(label_file_path, "w")
        # Se guarda el archivo y se agrega el comando para eliminar las imagenes que se requirieron en la máquina
        f.write(global_zpl + "^XA^IDR:*.GRF^FS^XZ")
        f.close()

        # Se manda a imprimir como raw
        job_id = conn.printFile(printer_name, label_file_path, "Label Print",
                                {"raw": "True"})

        print(job_id)
示例#5
0
 def test_image_to_zpl(self):
     grf = GRF.from_image(self._read_file('pdf-image.png'), 'TEST')
     grf.optimise_barcodes()
     self._compare(grf.to_zpl(copies=2), 'image-optimised-zb64-copies2.zpl')
示例#6
0
 def test_image_to_zpl(self):
     grf = GRF.from_image(self._read_file('pdf-image.png'), 'TEST')
     grf.optimise_barcodes()
     self._compare(grf.to_zpl(copies=2), 'image-optimised-zb64-copies2.zpl')