Exemple #1
0
def print_raster_graphic_unencoded( printer_socket ):
	""" Generate the PCL document containg a raw graphic image.
	    This sample is a basic implementation injecting raw esc sequences
	
	parameters:
		printer_socket : tuple (PRINTER_IP, PRINTER_PORT). On which
						 socket to print.
	"""
	
	print( 'Minimal Raster Graphic printing' )
	print( '-------------------------------' )
	print( 'Printer IP: %s\nPrinter Port: %i' % printer_socket )
	medium = PrinterSocketAdapter( printer_socket )
	
	# Very simple printout + usual initialization commands
	d = HpPclDocument( 'cp850', medium)
	d.reset_printer() # PCL to reset the printer

	d.write( u'Raster Graphic Test' )
    # Move the cursor to PCL unit position (300,400) within the PCL
    # coordinate system
    #   x-position: 300 unit @ 300 dot/inch --> 1 inch --> 2.54cm
    #   y-position: 400 unit @ 300 dot/inch --> 1.33 inch --> 3.38cm 
	d.cursor_move( (0,50) )
	
	# Set the Raster Graphics resolution (300 dpi)
	d.raster_set_resolution(300)
	
	# Raster Graphic Presentation Mode
	# -> Orientation of the logical page
	d.raster_presentation_mode() 
	 
	# Start Raster Graphic
	#  0 -> At x-position = 0
	#  1 -> At current x-position of the cursor position
	d.raster_start_graphic( at_current_cursor_pos = True ) 

	# Load the image present in local path
	# bitmap_tiny.bmp makes 716 pixels width & 818 pixels height.
	# @ raster_set_resolution = 300 dot per inch 
	# => 2.386 inch width x 2.726 inch width = ~6.060cm x ~6.92cm 
	image = misc.imread( 'bitmap.bmp', flatten='0' )
	print( "Image size (h,w) = (%i,%i)" % (len(image),len(image[0]) ) )

	d.raster_senddata_bitmap( image )

	# End Raster Graphic
	d.raster_end_graphic()
	
	# Move to position 
    # Move the cursor to PCL unit position (300,400) within the PCL
    # coordinate system
	d.cursor_move( (0, 50+818+10) ) # New height = Top image positition + image height + 10 dots

	d.writeln( u'End of test' )
		
	medium.open() # Open the media for transmission
	try:
		d.send() # Send the content of the current document
	finally:
		medium.close()
	
	del( d )
	del( medium )
Exemple #2
0
def print_raster_graphic_unencoded( printer_socket ):
	""" Generate the PCL document containg a raw graphic image.
	    This sample is a basic implementation injecting raw esc sequences
	
	parameters:
		printer_socket : tuple (PRINTER_IP, PRINTER_PORT). On which
						 socket to print.
	"""
	
	print( 'Minimal Raster Graphic printing' )
	print( '-------------------------------' )
	print( 'Printer IP: %s\nPrinter Port: %i' % printer_socket )
	medium = PrinterSocketAdapter( printer_socket )
	
	# Very simple printout + usual initialization commands
	d = HpPclDocument( 'cp850', medium)
	d.reset_printer() # PCL to reset the printer

	d.write( u'Raster Graphic Test' )
    # Move the cursor to PCL unit position (300,400) within the PCL
    # coordinate system
    #   x-position: 300 unit @ 300 dot/inch --> 1 inch --> 2.54cm
    #   y-position: 400 unit @ 300 dot/inch --> 1.33 inch --> 3.38cm 
	d.cursor_move( (300,400) )
	
	# Set the Raster Graphics resolution (75 dpi)
	d.raster_set_resolution()
	
	# Raster Graphic Presentation Mode
	# -> Orientation of the logical page
	d.raster_presentation_mode() 
	 
	# Start Raster Graphic
	#  0 -> At x-position = 0
	#  1 -> At current x-position of the cursor position
	d.raster_start_graphic( at_current_cursor_pos = True ) 

	# sending 5 rows of datas
	#   Source: "PCL 5 Printer Langage Technical Reference.pdf", page 339
	#	Raster Image Data                       Command Data
	# Dot
	# Row byte 1   byte 2   byte 3   byte 4     Decimal Equivalent
	# 1   00000000 00000000 10000000 00000000   <esc>*b4W[0, 0,128, 0]
	# 2   00000000 00000000 11000000 00000000   <esc>*b4W[0, 0,192, 0]
	# 3   00000000 00000000 11100000 00000000   <esc>*b4W[0, 0,224, 0]
	# 4   00000000 00000000 11110000 00000000   <esc>*b4W[0, 0,240, 0]
	# 5   00000000 00000000 11111000 00000000   <esc>*b4W[0, 0,248, 0]
	
	# Print the image, stored as list of bit (encoded into string for
	# easy code writing, use a space every 8 bits for reading, 
	# the code space are ignored)
	d.raster_senddata_str( ['00000000 00000000 10000000 00000000',
							'01100110 00000000 11000000 00000000', 
							'00100010 01000000 11100000 00000000', 
							'10000000 10000000 11110000 00000000', 
							'01111111 00000000 11111000 0000000' ] )

	# End Raster Graphic
	d.raster_end_graphic()
	
	# Move to position 
    # Move the cursor to PCL unit position (300,400) within the PCL
    # coordinate system
    #    This example use the 300 dots/inch as refernce for coordonate
    #    y-pos = under the raster --> 4 cm --> 1.57 inch @ 300 dot/inch --> 472 dots
	d.cursor_move( (300, 472) )

	d.writeln( u'End of test' )
		
	medium.open() # Open the media for transmission
	try:
		d.send() # Send the content of the current document
	finally:
		medium.close()
	
	del( d )
	del( medium )