示例#1
0
def print_minimal_doc( ):
	""" Print the minimal document on Zebra. """
	
	print( 'Print the minimal ZPL document' )
	print( '------------------------------' )
	medium = PrinterCupsAdapter( printer_queue_name = PRINTER_QUEUE_NAME )
	d = ZplDocument( target_encoding = PRINTER_ENCODING, printer_adapter = medium, title = 'Minimal doc' )
	
	# Start a Print format
	d.format_start()
	
	# Write a field by assigning a font + size
	d.field( origin=(100,50), font=d.font('D',30,20), data=u'MC Hobby' )
	
	# write a second field by using default setting
	# Origin Y is set to 80. 80 = 50 (Y position here upper) + 30 (font height here upper).
	d.field( origin=(100,80), font=d.font('C'), data=u'Fun electronic hacking' ) 
	
	# End Print format
	d.format_end()

	
	medium.open() # Open the media for transmission. 
				  # With CUPS medium this open a temporary file
	try:
		d.send()  # With CUPS medium this send the data to the temporary file
		medium.flush() # With CUPS medium this close the temporary file and
		               #   sends to file to the print queue  
	finally:
		medium.close()  
		               
	
	del( medium )
示例#2
0
def print_warranty_label_large(prefix_text, counter_start, label_count):
    """ Print the Warranty Label on the GK420t on 70mm width x 2.5mm height labels """
    #print product_id
    #print product_ref
    #print product_ean
    #print qty
    medium = PrinterCupsAdapter(
        printer_queue_name=PRINTER_LARGELABEL_QUEUE_NAME)

    for label_counter in range(label_count):
        d = ZplDocument(
            target_encoding=PRINTER_ENCODING,
            printer_adapter=medium,
            title='Warranty %s for %i' %
            (prefix_text, counter_start + counter_start + label_counter))

        # Start a Print format
        d.format_start()

        # Write a BarCode field
        d.field(origin=(175, 11),
                font=d.font('T', 17, 8),
                data=unicode('Garantie / Warranty'))  # use font E as default
        d.field(origin=(175, 62),
                font=d.font('T', 17, 8),
                data=unicode('%s-%i' %
                             (prefix_text, counter_start +
                              label_counter)))  # use font E as default

        #d.ean13( origin=(500,62), ean=unicode(product_ean), height_dots = 50 )
        # d.field( origin=(630,160), font=d.font('T',17,8), data=unicode( product_id ).rjust(4) ) # use font E by default

        d.field(origin=(175, 120),
                font=d.font('C'),
                data=u'Pour vos garanties, vous les conditions')
        d.field(origin=(175, 145),
                font=d.font('C'),
                data=u'générales de ventes sur shop.mchobby.be')

        # End Print format
        d.format_end()

        medium.open()  # Open the media for transmission.
        # With CUPS medium this open a temporary file
        try:
            d.send(
            )  # With CUPS medium this send the data to the temporary file
            medium.flush(
            )  # With CUPS medium this close the temporary file and
        #   sends to file to the print queue
        finally:
            medium.close()
            del (d)

    del (medium)
示例#3
0
def list_cups_printer():
    """ List the cups printer available on the system. """

    print('List CUPS printer')
    print('-----------------')
    medium = PrinterCupsAdapter()

    medium.open()  # Open the media for transmission
    try:
        medium.dump_printers()
    finally:
        medium.close()

    del (medium)
示例#4
0
def print_product_label_large(product_id, product_ref, product_ean, qty):
    """ Print the Labels on the GK420t on 70mm width x 2.5mm height labels """
    #print product_id
    #print product_ref
    #print product_ean
    #print qty
    medium = PrinterCupsAdapter(
        printer_queue_name=PRINTER_LARGELABEL_QUEUE_NAME)
    d = ZplDocument(target_encoding=PRINTER_ENCODING,
                    printer_adapter=medium,
                    title='%i x %s' % (qty, product_ref))

    # Start a Print format
    d.format_start()

    # Set Quantity
    if qty > 1:
        d.print_quantity(qty)

    # Write a BarCode field
    d.field(origin=(175, 11),
            font=d.font('T', 17, 8),
            data=unicode(product_ref))  # use font E as default

    d.ean13(origin=(500, 62), ean=unicode(product_ean), height_dots=50)
    d.field(origin=(630, 160),
            font=d.font('T', 17, 8),
            data=unicode(product_id).rjust(4))  # use font E by default

    d.field(origin=(225, 150),
            font=d.font('C'),
            data=u'MC Hobby sprl - shop.mchobby.be')
    d.field(origin=(255, 175),
            font=d.font('C'),
            data=u'Happy Electronic Hacking!')

    # End Print format
    d.format_end()

    medium.open()  # Open the media for transmission.
    # With CUPS medium this open a temporary file
    try:
        d.send()  # With CUPS medium this send the data to the temporary file
        medium.flush()  # With CUPS medium this close the temporary file and
        #   sends to file to the print queue
    finally:
        medium.close()

    del (medium)
示例#5
0
def print_ondemand_label_short(label_title, label_lines, qty):
    """ Print the Labels on the LP2824 on small labels 
	
	label_title: title on the label, lines 1 & two in extra bold
	label_lines: list of unicode to be printed (up to 5 lines)"""
    #print product_id
    #print product_ref
    #print product_ean
    #print qty
    medium = PrinterCupsAdapter(
        printer_queue_name=PRINTER_SHORTLABEL_QUEUE_NAME)
    d = ZplDocument(target_encoding=PRINTER_ENCODING,
                    printer_adapter=medium,
                    title='%i x %s' % (qty, label_title))

    # Start a Print format
    d.format_start()

    # Set Quantity
    if qty > 1:
        d.print_quantity(qty)

    # Write a BarCode field
    d.field(origin=(120, 11),
            font=d.font('E'),
            data=unicode(label_title.ljust(20)[:10]))
    d.field(origin=(120, 42),
            font=d.font('E'),
            data=unicode(label_title.ljust(20)[10:]))
    top = 75
    for line in label_lines:
        d.field(origin=(98, top), font=d.font('C'), data=line)
        top = top + 25

    # End Print format
    d.format_end()

    medium.open()  # Open the media for transmission.
    # With CUPS medium this open a temporary file
    try:
        d.send()  # With CUPS medium this send the data to the temporary file
        medium.flush()  # With CUPS medium this close the temporary file and
        #   sends to file to the print queue
    finally:
        medium.close()

    del (medium)
示例#6
0
def list_cups_printer( ):
	""" List the cups printer available on the system. """
	
	print( 'List CUPS printer' )
	print( '-----------------' )
	medium = PrinterCupsAdapter()
	
	medium.open() # Open the media for transmission
	try:
		medium.dump_printers()
	finally:
		medium.close()
	
	del( medium )
示例#7
0
def print_ondemand_label_large(label_title, label_lines, qty):
    """ Print the Labels on the GK420t on 70mm width x 2.5mm height labels 
	
	label_title: title on the label, first line in extra bold
	label_lines: list of unicode to be printed (up to 5 lines)"""
    #print product_id
    #print product_ref
    #print product_ean
    #print qty
    medium = PrinterCupsAdapter(
        printer_queue_name=PRINTER_LARGELABEL_QUEUE_NAME)
    d = ZplDocument(target_encoding=PRINTER_ENCODING,
                    printer_adapter=medium,
                    title='%i x %s' % (qty, label_title))

    # Start a Print format
    d.format_start()

    # Set Quantity
    if qty > 1:
        d.print_quantity(qty)

    # Write a BarCode field
    d.field(origin=(175, 11),
            font=d.font('T', 17, 8),
            data=unicode(label_title))  # use font E as default
    top = 62
    for line in label_lines:
        d.field(origin=(175, top), font=d.font('C'), data=line)
        top = top + 25

    # End Print format
    d.format_end()

    medium.open()  # Open the media for transmission.
    # With CUPS medium this open a temporary file
    try:
        d.send()  # With CUPS medium this send the data to the temporary file
        medium.flush()  # With CUPS medium this close the temporary file and
        #   sends to file to the print queue
    finally:
        medium.close()

    del (medium)
示例#8
0
def print_ondemand_label_kingsize(label_title, label_title2):
    """ Print the Labels on the GK420t on 70mm width x 2.5mm height labels 
	
	label_title: title on the label (the only text to print) """
    qty = 1  # Print only one label

    medium = PrinterCupsAdapter(
        printer_queue_name=PRINTER_LARGELABEL_QUEUE_NAME)
    d = ZplDocument(target_encoding=PRINTER_ENCODING,
                    printer_adapter=medium,
                    title='%i x %s' % (qty, label_title))

    # Start a Print format
    d.format_start()

    # Set Quantity
    if qty > 1:
        d.print_quantity(qty)
    d.field(origin=(125, 11),
            font=d.font('V', 80, 71),
            data=unicode(label_title))
    if len(label_title2) > 0:
        d.field(origin=(125, 11 + 80),
                font=d.font('V', 80, 71),
                data=unicode(label_title2))

    #top = 62
    #for line in label_lines:
    #	d.field( origin=(175, top), font=d.font('C'), data=line )
    #	top = top + 25

    # End Print format
    d.format_end()

    medium.open()  # Open the media for transmission.
    # With CUPS medium this open a temporary file
    try:
        d.send()  # With CUPS medium this send the data to the temporary file
        medium.flush()  # With CUPS medium this close the temporary file and
        #   sends to file to the print queue
    finally:
        medium.close()

    del (medium)
示例#9
0
def print_quantity_doc():
    """ Print the ean13 document IN MULTIPLE QUANTITY on Zebra. """

    # 3232 is used for belgian courrier, let say the following '1' to identify product and 576 for id_product
    ean_base = '323210000576'
    ean13 = calculate_ean13(ean_base)
    print ean13

    print('Print the EAN13 (%02i) ZPL document' % PRINTER_QUANTITY)
    print('----------------------------------')
    medium = PrinterCupsAdapter(printer_queue_name=PRINTER_QUEUE_NAME)
    d = ZplDocument(target_encoding=PRINTER_ENCODING,
                    printer_adapter=medium,
                    title='Barcode doc x %i' % PRINTER_QUANTITY)

    # Start a Print format
    d.format_start()

    # Set Quantity
    d.print_quantity(PRINTER_QUANTITY)

    # Write a BarCode field
    d.field(origin=(120, 11), font=d.font('E'), data=u'RASPBERRY.')
    d.field(origin=(120, 42), font=d.font('E'), data=u'Pi.2......')
    d.ean13(origin=(130, 80), ean=unicode(ean13), height_dots=50)

    d.field(origin=(140, 160), font=d.font('C'), data=u'MC Hobby sprl')
    d.field(origin=(130, 180), font=d.font('C'), data=u'shop.mchobby.be')
    # End Print format
    d.format_end()

    medium.open()  # Open the media for transmission.
    # With CUPS medium this open a temporary file
    try:
        d.send()  # With CUPS medium this send the data to the temporary file
        medium.flush()  # With CUPS medium this close the temporary file and
        #   sends to file to the print queue
    finally:
        medium.close()

    del (medium)
示例#10
0
def print_ondemand_label_short( label_title, label_lines, qty ):
	""" Print the Labels on the LP2824 on small labels 
	
	label_title: title on the label, lines 1 & two in extra bold
	label_lines: list of unicode to be printed (up to 5 lines)"""
	#print product_id
	#print product_ref
	#print product_ean
	#print qty
	medium = PrinterCupsAdapter( printer_queue_name = PRINTER_SHORTLABEL_QUEUE_NAME )
	d = ZplDocument( target_encoding = PRINTER_ENCODING, printer_adapter = medium, title = '%i x %s' % (qty,label_title) )
	
	# Start a Print format
	d.format_start()
	
	# Set Quantity 
	if qty > 1:
		d.print_quantity( qty )

	# Write a BarCode field
	d.field( origin=(120,11), font=d.font('E'), data= unicode( label_title.ljust(20)[:10] ) )
	d.field( origin=(120,42), font=d.font('E'), data= unicode( label_title.ljust(20)[10:] ) )
	top = 75
	for line in label_lines:
		d.field( origin=(98, top), font=d.font('C'), data=line )
		top = top + 25
	
	# End Print format
	d.format_end()

	
	medium.open() # Open the media for transmission. 
				  # With CUPS medium this open a temporary file
	try:
		d.send()  # With CUPS medium this send the data to the temporary file
		medium.flush() # With CUPS medium this close the temporary file and
		               #   sends to file to the print queue  
	finally:
		medium.close()  
		               
	
	del( medium )
示例#11
0
def print_warranty_label_large( prefix_text, counter_start, label_count ):
	""" Print the Warranty Label on the GK420t on 70mm width x 2.5mm height labels """
	#print product_id
	#print product_ref
	#print product_ean
	#print qty
	medium = PrinterCupsAdapter( printer_queue_name = PRINTER_LARGELABEL_QUEUE_NAME )

	for label_counter in range( label_count ):
		d = ZplDocument( target_encoding = PRINTER_ENCODING, printer_adapter = medium, title = 'Warranty %s for %i' % (prefix_text, counter_start+counter_start + label_counter) )
	
		# Start a Print format
		d.format_start()

		# Write a BarCode field
		d.field( origin=(175,11), font=d.font('T',17,8), data= unicode( 'Garantie / Warranty') ) # use font E as default
		d.field( origin=(175,62), font=d.font('T',17,8), data= unicode( '%s-%i' % (prefix_text, counter_start + label_counter) ) )# use font E as default
	
		#d.ean13( origin=(500,62), ean=unicode(product_ean), height_dots = 50 )
		# d.field( origin=(630,160), font=d.font('T',17,8), data=unicode( product_id ).rjust(4) ) # use font E by default
		
		d.field( origin=(175,120), font=d.font('C'), data=u'Pour vos garanties, vous les conditions' )
		d.field( origin=(175,145), font=d.font('C'), data=u'générales de ventes sur shop.mchobby.be' )
	

		# End Print format
		d.format_end()

	
		medium.open() # Open the media for transmission. 
					  # With CUPS medium this open a temporary file
		try:
			d.send()  # With CUPS medium this send the data to the temporary file
			medium.flush() # With CUPS medium this close the temporary file and
		               #   sends to file to the print queue  
		finally:
			medium.close()
			del( d )  
		
	
	del( medium )
示例#12
0
def print_ondemand_label_large( label_title, label_lines, qty ):
	""" Print the Labels on the GK420t on 70mm width x 2.5mm height labels 
	
	label_title: title on the label, first line in extra bold
	label_lines: list of unicode to be printed (up to 5 lines)"""
	#print product_id
	#print product_ref
	#print product_ean
	#print qty
	medium = PrinterCupsAdapter( printer_queue_name = PRINTER_LARGELABEL_QUEUE_NAME )
	d = ZplDocument( target_encoding = PRINTER_ENCODING, printer_adapter = medium, title = '%i x %s' % (qty,label_title) )
	
	# Start a Print format
	d.format_start()
	
	# Set Quantity 
	if qty > 1:
		d.print_quantity( qty )

	# Write a BarCode field
	d.field( origin=(175,11), font=d.font('T',17,8), data= unicode(label_title) ) # use font E as default
	top = 62
	for line in label_lines:
		d.field( origin=(175, top), font=d.font('C'), data=line )
		top = top + 25
	
	# End Print format
	d.format_end()

	
	medium.open() # Open the media for transmission. 
				  # With CUPS medium this open a temporary file
	try:
		d.send()  # With CUPS medium this send the data to the temporary file
		medium.flush() # With CUPS medium this close the temporary file and
		               #   sends to file to the print queue  
	finally:
		medium.close()  
		               
	
	del( medium )
示例#13
0
def print_product_label_large( product_id, product_ref, product_ean, qty ):
	""" Print the Labels on the GK420t on 70mm width x 2.5mm height labels """
	#print product_id
	#print product_ref
	#print product_ean
	#print qty
	medium = PrinterCupsAdapter( printer_queue_name = PRINTER_LARGELABEL_QUEUE_NAME )
	d = ZplDocument( target_encoding = PRINTER_ENCODING, printer_adapter = medium, title = '%i x %s' % (qty,product_ref) )
	
	# Start a Print format
	d.format_start()
	
	# Set Quantity 
	if qty > 1:
		d.print_quantity( qty )

	# Write a BarCode field
	d.field( origin=(175,11), font=d.font('T',17,8), data= unicode( product_ref) ) # use font E as default
	
	d.ean13( origin=(500,62), ean=unicode(product_ean), height_dots = 50 )
	d.field( origin=(630,160), font=d.font('T',17,8), data=unicode( product_id ).rjust(4) ) # use font E by default
		
	d.field( origin=(225,150), font=d.font('C'), data=u'MC Hobby sprl - shop.mchobby.be' )
	d.field( origin=(255,175), font=d.font('C'), data=u'Happy Electronic Hacking!' )
	

	# End Print format
	d.format_end()

	
	medium.open() # Open the media for transmission. 
				  # With CUPS medium this open a temporary file
	try:
		d.send()  # With CUPS medium this send the data to the temporary file
		medium.flush() # With CUPS medium this close the temporary file and
		               #   sends to file to the print queue  
	finally:
		medium.close()  
		               
	
	del( medium )
示例#14
0
def print_barcode39_doc():
    """ Print the Barcode39 document on Zebra. """

    print('Print the Barcode39 ZPL document')
    print('--------------------------------')
    medium = PrinterCupsAdapter(printer_queue_name=PRINTER_QUEUE_NAME)
    d = ZplDocument(target_encoding=PRINTER_ENCODING,
                    printer_adapter=medium,
                    title='Barcode doc')

    # Start a Print format
    d.format_start()

    # Origin Y is set to 80. 80 = 50 (Y position here upper) + 30 (font height here upper).
    #d.field( origin=(100,80), font=d.font('C'), data=u'Fun electronic hacking' )

    # Write a BarCode field
    d.field(origin=(120, 11), font=d.font('E'), data=u'RASPBERRY.')
    d.field(origin=(120, 42), font=d.font('E'), data=u'Pi.2......')
    d.barcode39(origin=(110, 80), data=u'P0576', height_dots=50)

    d.field(origin=(140, 160), font=d.font('C'), data=u'MC Hobby sprl')
    d.field(origin=(130, 180), font=d.font('C'), data=u'shop.mchobby.be')
    # End Print format
    d.format_end()

    medium.open()  # Open the media for transmission.
    # With CUPS medium this open a temporary file
    try:
        d.send()  # With CUPS medium this send the data to the temporary file
        medium.flush()  # With CUPS medium this close the temporary file and
        #   sends to file to the print queue
    finally:
        medium.close()

    del (medium)
示例#15
0
def print_quantity_doc( ):
	""" Print the ean13 document IN MULTIPLE QUANTITY on Zebra. """
		
	# 3232 is used for belgian courrier, let say the following '1' to identify product and 576 for id_product
	ean_base = '323210000576'   
	ean13 = calculate_ean13( ean_base )
	print ean13
	
	print( 'Print the EAN13 (%02i) ZPL document' % PRINTER_QUANTITY )
	print( '----------------------------------' )
	medium = PrinterCupsAdapter( printer_queue_name = PRINTER_QUEUE_NAME )
	d = ZplDocument( target_encoding = PRINTER_ENCODING, printer_adapter = medium, title = 'Barcode doc x %i' % PRINTER_QUANTITY )
	
	# Start a Print format
	d.format_start()
	
	# Set Quantity 
	d.print_quantity( PRINTER_QUANTITY )

	# Write a BarCode field
	d.field( origin=(120,11), font=d.font('E'), data=u'RASPBERRY.' )
	d.field( origin=(120,42), font=d.font('E'), data=u'Pi.2......' )
	d.ean13( origin=(130,80), ean=unicode(ean13), height_dots = 50 )
	
	d.field( origin=(140,160), font=d.font('C'), data=u'MC Hobby sprl' )
	d.field( origin=(130,180), font=d.font('C'), data=u'shop.mchobby.be' )
	# End Print format
	d.format_end()

	
	medium.open() # Open the media for transmission. 
				  # With CUPS medium this open a temporary file
	try:
		d.send()  # With CUPS medium this send the data to the temporary file
		medium.flush() # With CUPS medium this close the temporary file and
		               #   sends to file to the print queue  
	finally:
		medium.close()  
		               
	
	del( medium )
示例#16
0
def print_ondemand_label_kingsize( label_title, label_title2 ):
	""" Print the Labels on the GK420t on 70mm width x 2.5mm height labels 
	
	label_title: title on the label (the only text to print) """
	qty = 1 # Print only one label

	medium = PrinterCupsAdapter( printer_queue_name = PRINTER_LARGELABEL_QUEUE_NAME )
	d = ZplDocument( target_encoding = PRINTER_ENCODING, printer_adapter = medium, title = '%i x %s' % (qty,label_title) )
	
	# Start a Print format
	d.format_start()
	
	# Set Quantity 
	if qty > 1:
		d.print_quantity( qty )	
	d.field( origin=(125,11), font=d.font('V',80,71), data= unicode(label_title) ) 
	if len( label_title2 )>0:
		d.field( origin=(125,11+80), font=d.font('V',80,71), data= unicode(label_title2) ) 
		
	#top = 62
	#for line in label_lines:
	#	d.field( origin=(175, top), font=d.font('C'), data=line )
	#	top = top + 25
	
	# End Print format
	d.format_end()

	
	medium.open() # Open the media for transmission. 
				  # With CUPS medium this open a temporary file
	try:
		d.send()  # With CUPS medium this send the data to the temporary file
		medium.flush() # With CUPS medium this close the temporary file and
		               #   sends to file to the print queue  
	finally:
		medium.close()  
		               
	
	del( medium )
示例#17
0
def print_barcode39_doc( ):
	""" Print the Barcode39 document on Zebra. """
	
	print( 'Print the Barcode39 ZPL document' )
	print( '--------------------------------' )
	medium = PrinterCupsAdapter( printer_queue_name = PRINTER_QUEUE_NAME )
	d = ZplDocument( target_encoding = PRINTER_ENCODING, printer_adapter = medium, title = 'Barcode doc' )
	
	# Start a Print format
	d.format_start()

	# Origin Y is set to 80. 80 = 50 (Y position here upper) + 30 (font height here upper).
	#d.field( origin=(100,80), font=d.font('C'), data=u'Fun electronic hacking' ) 
	
	# Write a BarCode field
	d.field( origin=(120,11), font=d.font('E'), data=u'RASPBERRY.' )
	d.field( origin=(120,42), font=d.font('E'), data=u'Pi.2......' )
	d.barcode39( origin=(110,80), data=u'P0576', height_dots = 50 )
	
	d.field( origin=(140,160), font=d.font('C'), data=u'MC Hobby sprl' )
	d.field( origin=(130,180), font=d.font('C'), data=u'shop.mchobby.be' )
	# End Print format
	d.format_end()

	
	medium.open() # Open the media for transmission. 
				  # With CUPS medium this open a temporary file
	try:
		d.send()  # With CUPS medium this send the data to the temporary file
		medium.flush() # With CUPS medium this close the temporary file and
		               #   sends to file to the print queue  
	finally:
		medium.close()  
		               
	
	del( medium )
示例#18
0
def print_product_label( product_id, product_ref, product_ean, qty ):
	""" Print the Labels on the Zebra LP 2824 on 1.25" x 1" labels """
	#print product_id
	#print product_ref
	#print product_ean
	#print qty
	medium = PrinterCupsAdapter( printer_queue_name = PRINTER_SHORTLABEL_QUEUE_NAME )
	d = ZplDocument( target_encoding = PRINTER_ENCODING, printer_adapter = medium, title = '%i x %s' % (qty,product_ref) )
	
	# Start a Print format
	d.format_start()
	
	# Set Quantity 
	if qty > 1:
		d.print_quantity( qty )

	# Label is printed with 2 lines of 10 characters
	l1 = product_ref[:10] 
	l2 = product_ref[10:]
	
	# Write product name
	#   we will try to offer a human redeable text (2x10 chars) on the  
	#   label properly cut the text around ' ', '-'
	iPos = max( l1.rfind( ' ' ), l1.rfind( '-' ) )
	if iPos == -1 or iPos == 9 or len( product_ref ) <= 10: 
		# The text too short or not appropriate to cute it.
        # Just cut it without care.
		l1 = product_ref.ljust(20)[:10] 
		l2 = product_ref.ljust(20)[10:]
	else:
		iShouldMove = 10 - (iPos+1)
		if len( l2 )+ iShouldMove <= 10: # if second line would not exceed max len ?
			# We go for nicely cutting it!
			l2 = l1[iPos+1:] + l2
			l1 = l1[:iPos+1] 
		else:
			# Keep the cut without care
			l1 = product_ref.ljust(20)[:10] 
			l2 = product_ref.ljust(20)[10:]
			
	
	d.field( origin=(120,11), font=d.font('E'), data= unicode( l1 ) )
	d.field( origin=(120,42), font=d.font('E'), data= unicode( l2 ) )
	# Write a BarCode field
	d.ean13( origin=(130,80), ean=unicode(product_ean), height_dots = 50 )
	
	d.field( origin=(130,160), font=d.font('C'), data=u'shop.mchobby.be' )
	d.field( origin=(98,185), font=d.font('C'), data=u'MC Hobby sprl' )
	
	d.field( origin=(265,185), font=d.font('E',17,8), data=unicode( product_id ).rjust(4) )
	# End Print format
	d.format_end()

	
	medium.open() # Open the media for transmission. 
				  # With CUPS medium this open a temporary file
	try:
		d.send()  # With CUPS medium this send the data to the temporary file
		medium.flush() # With CUPS medium this close the temporary file and
		               #   sends to file to the print queue  
	finally:
		medium.close()  
		               
	
	del( medium )
示例#19
0
def print_product_label(product_id, product_ref, product_ean, qty):
    """ Print the Labels on the Zebra LP 2824 on 1.25" x 1" labels """
    #print product_id
    #print product_ref
    #print product_ean
    #print qty
    medium = PrinterCupsAdapter(
        printer_queue_name=PRINTER_SHORTLABEL_QUEUE_NAME)
    d = ZplDocument(target_encoding=PRINTER_ENCODING,
                    printer_adapter=medium,
                    title='%i x %s' % (qty, product_ref))

    # Start a Print format
    d.format_start()

    # Set Quantity
    if qty > 1:
        d.print_quantity(qty)

    # Label is printed with 2 lines of 10 characters
    l1 = product_ref[:10]
    l2 = product_ref[10:]

    # Write product name
    #   we will try to offer a human redeable text (2x10 chars) on the
    #   label properly cut the text around ' ', '-'
    iPos = max(l1.rfind(' '), l1.rfind('-'))
    if iPos == -1 or iPos == 9 or len(product_ref) <= 10:
        # The text too short or not appropriate to cute it.
        # Just cut it without care.
        l1 = product_ref.ljust(20)[:10]
        l2 = product_ref.ljust(20)[10:]
    else:
        iShouldMove = 10 - (iPos + 1)
        if len(
                l2
        ) + iShouldMove <= 10:  # if second line would not exceed max len ?
            # We go for nicely cutting it!
            l2 = l1[iPos + 1:] + l2
            l1 = l1[:iPos + 1]
        else:
            # Keep the cut without care
            l1 = product_ref.ljust(20)[:10]
            l2 = product_ref.ljust(20)[10:]

    d.field(origin=(120, 11), font=d.font('E'), data=unicode(l1))
    d.field(origin=(120, 42), font=d.font('E'), data=unicode(l2))
    # Write a BarCode field
    d.ean13(origin=(130, 80), ean=unicode(product_ean), height_dots=50)

    d.field(origin=(130, 160), font=d.font('C'), data=u'shop.mchobby.be')
    d.field(origin=(98, 185), font=d.font('C'), data=u'MC Hobby sprl')

    d.field(origin=(265, 185),
            font=d.font('E', 17, 8),
            data=unicode(product_id).rjust(4))
    # End Print format
    d.format_end()

    medium.open()  # Open the media for transmission.
    # With CUPS medium this open a temporary file
    try:
        d.send()  # With CUPS medium this send the data to the temporary file
        medium.flush()  # With CUPS medium this close the temporary file and
        #   sends to file to the print queue
    finally:
        medium.close()

    del (medium)