def test_direct():
	""" Demontrate usage of the HpPclDocument list structure. You should
	use the exposed method. """
	 
	print ('Direct HpPclDocument appending' )
	print ('------------------------------' )
	d = HpPclDocument()
	d.append( (PCL_DATA_TYPE.PCL, u'test' ) )
	d.append( (PCL_DATA_TYPE.TEXT, u'test2' ) )
	d.append( (PCL_DATA_TYPE.TEXT, u'test3' ) )
	d = d +  (1, u'test4') 

	print( '#items: %i' % len(d) )
	print( d )
	del( d )
Exemple #2
0
def test_minimal_doc():
    """ Generate the mininal PCL document """

    print('Minimal HpPclDocument')
    print('---------------------')
    d = HpPclDocument()
    d.reset_printer()
    d.write(u'This is my first document')
    d.write(u'which accept ecute é and others')

    print('#items: %i' % len(d))
    print(d)
    del (d)
def test_minimal_doc():
	""" Generate the mininal PCL document """
	
	print( 'Minimal HpPclDocument' )
	print( '---------------------' )
	d = HpPclDocument()
	d.reset_printer()
	d.write( u'This is my first document' )
	d.write( u'which accept ecute é and others' )
	
	print( '#items: %i' % len(d) )
	print( d )
	del( d )
Exemple #4
0
def test_direct():
    """ Demontrate usage of the HpPclDocument list structure. You should
	use the exposed method. """

    print('Direct HpPclDocument appending')
    print('------------------------------')
    d = HpPclDocument()
    d.append((PCL_DATA_TYPE.PCL, u'test'))
    d.append((PCL_DATA_TYPE.TEXT, u'test2'))
    d.append((PCL_DATA_TYPE.TEXT, u'test3'))
    d = d + (1, u'test4')

    print('#items: %i' % len(d))
    print(d)
    del (d)
Exemple #5
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 #6
0
def print_barcode_doc(printer_socket):
    """ Generate the mininal PCL document INCLUDING CODE39 BARCODE
	and print it on network printer.
	
	parameters:
		printer_socket : tuple (PRINTER_IP, PRINTER_PORT). On which
						 socket to print.
	"""

    print('Minimal Barcode Document 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.spacing()  # Set the default Fixed spacing
    d.pitch()  # Default 10 characters per inch
    d.horizontal_motion_index(
    )  # Set the default HMI to 0 = no horizontal motion
    d.paper_source(
    )  # Set the default paper source to Tray + eject current page if any.
    d.symbol_set()  # Set the default symbol set (PC-850)

    d.writeln(u'This a demonstration document')
    d.writeln(u'including BarCode39 generation')
    d.writeln()
    d.writeln(u'You can read the barcode with a product like Barcode')
    d.writeln(u' Reader/Scanner Module - CCD Camera - USB Interface')
    d.writeln(u'Such module is available at http://shop.mchobby.be')
    d.writeln(u'Those module are usually configured for Qwerty Keyboards')
    d.writeln(u' where numbers are accessible on the first row')
    d.writeln(u'When using French keyboards, you have to press the')
    d.writeln(u' Shift key (or Shift Lock) to activate the numeric')
    d.writeln(u' value on the first row')
    d.writeln(u'Surprisingly, on Linux Mint, you have to press down the')
    d.writeln(u' RIGHT SHIFT KEY to activate numbers on the first row!')
    d.writeln(u' The best option is certainly to reconfigure your scanner')
    d.writeln()
    d.writeln(u'Now, enjoy the Barcode 39 reading with your scanner :-) ')
    d.writeln()

    bc = Barcode39(d)  # Owner must be the document
    bc.write(u'MCHP00189')  # Write the bar code into the document
    d.writeln()
    d.writeln('    ' + bc.barcode_message(u'MCHP00189'))
    d.writeln()

    d.pitch(15)  # 15 characters per inch
    bc.write(u'GGN00030365')  # Write the barcode in the document
    d.writeln()
    d.writeln('    ' + bc.barcode_message(u'GGN00030365'))

    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 #7
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.write_esc(u'*p%ix%iY' % (300, 400))

    # Set the Raster Graphics resolution (75 dpi)
    d.write_esc(u'*t%iR' % (75))

    # Raster Graphic Presentation Mode
    # -> Orientation of the logical page
    d.write_esc(u'*r%iF' % (0))

    # Start Raster Graphic
    #  0 -> At x-position = 0
    #  1 -> At current x-position of the cursor position
    d.write_esc(u'*r%iA' % (1))

    # 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]
    def arr_to_bytes(lst):
        """ this function produce a "bytes" type from list of ASCII code 
		
		    arr_to_bytes( [0,0,248,0] ) -> '\x00\x00\xf8\x00' 
		"""
        return bytes(''.join([chr(x) for x in lst]))

    d.write_esc(u'*b4W')
    d.write_bytes(arr_to_bytes([0, 0, 128, 0]))
    d.write_esc(u'*b4W')
    d.write_bytes(arr_to_bytes([0, 0, 192, 0]))
    d.write_esc(u'*b4W')
    d.write_bytes(arr_to_bytes([0, 0, 224, 0]))
    d.write_esc(u'*b4W')
    d.write_bytes(arr_to_bytes([0, 0, 240, 0]))
    d.write_esc(u'*b4W')
    d.write_bytes(arr_to_bytes([0, 0, 248, 0]))

    # End Raster Graphic
    d.write_esc(u'*rC')

    # 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.write_esc(u'*p%ix%iY' % (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)
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.write_esc( u'*p%ix%iY' % (300,400) )
	
	# Set the Raster Graphics resolution (75 dpi)
	d.write_esc( u'*t%iR' % (75) )
	
	# Raster Graphic Presentation Mode
	# -> Orientation of the logical page
	d.write_esc( u'*r%iF' % (0) )
	 
	# Start Raster Graphic
	#  0 -> At x-position = 0
	#  1 -> At current x-position of the cursor position
	d.write_esc( u'*r%iA' % (1) )

	# 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]
	def arr_to_bytes( lst ):
		""" this function produce a "bytes" type from list of ASCII code 
		
		    arr_to_bytes( [0,0,248,0] ) -> '\x00\x00\xf8\x00' 
		"""
		return bytes( ''.join( [ chr(x) for x in lst ] ) )

	d.write_esc( u'*b4W' )
	d.write_bytes( arr_to_bytes( [0,0,128,0] ) )
	d.write_esc( u'*b4W' )
	d.write_bytes( arr_to_bytes( [0,0,192,0] ) )
	d.write_esc( u'*b4W' )
	d.write_bytes( arr_to_bytes( [0,0,224,0] ) )
	d.write_esc( u'*b4W' )
	d.write_bytes( arr_to_bytes( [0,0,240,0] ) )
	d.write_esc( u'*b4W' )
	d.write_bytes( arr_to_bytes( [0,0,248,0] ) )

	# End Raster Graphic
	d.write_esc( u'*rC' )
	
	# 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.write_esc( u'*p%ix%iY' % (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 )
Exemple #9
0
def print_hmi_demo( printer_socket ):
	""" Generate the PCL document printing a same line 
		with various Horizontal Motion Index values (HMI).
		
	parameters:
		printer_socket : tuple (PRINTER_IP, PRINTER_PORT). On which
						 socket to print.
	"""
	
	print( 'Horizontal Motion Index demo' )
	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.symbol_set()    # Set the default symbol set (PC-850)
	d.paper_source()  # Set the default paper source to Tray + eject current page if any.
	
	d.pitch( 10 )     # Set 10 cpi size characters
	hmi_start = 11 # Value corresponding to pitch = 10 cpi.
	
	# How to calculate the default/starting HMI value
	#               (see technical reference on Horizontal Motion Index)
    #
    #  A4 Width (inch) = 2338 dots wide / 300 dpi = 7.793 Inches
    #
    #  Lets say we want 80 chars per lines.
    #  cpi = 80 characters per line / 7.793 Inch wide = 10.266 cpi
    #        so call d.pitch( 10 ) to fix font size to 10 cpi
    #
    #  HMI value = 120 HMI Units / 10.266 char per inch = 11.689 
    #        so HMI starts at 11 (or 12 if you prefer). 
    #        over that value, the printed caracter will be "more espaced"
  

    # Increasing the horizontal motion index to put more space between
    # characters.
	for hmi_value in range( hmi_start, hmi_start + 10 ): 
		d.horizontal_motion_index( hmi_value ) 
		d.writeln( u'0123456789abcdef' )
			
	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 #10
0
def print_hmi_demo( printer_socket ):
	""" Generate the PCL document printing a same line 
		with various Horizontal Motion Index values (HMI).
		
	parameters:
		printer_socket : tuple (PRINTER_IP, PRINTER_PORT). On which
						 socket to print.
	"""
	
	print( 'Horizontal Motion Index demo' )
	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.symbol_set()    # Set the default symbol set (PC-850)
	d.paper_source()  # Set the default paper source to Tray + eject current page if any.
	
	d.pitch( 10 )     # Set 10 cpi size characters
	vmi_start = 6     # Value corresponding to pitch = 10 cpi.
	
	# How to calculate the default/starting VMI value
	#               (see technical reference on Vertical Motion Index)
    #
    # Common setting:
	#	  vmi = 7.27 -> allow to print 66 lines on a portrait page
	#	                 (with a half inch margin on the top and bottom)
	#	       (10 inch-height / 66 lines-per-page ) x 48 = 7.27 
	#	       
	#	  vmi = 5.45 -> allow to print 66 lines on a landscape letter page
	#	                 (with a half inch margin on the top and bottom)
    #
	#	       (7.5 inch-heigh / 66 lines-per-page ) x 48 = 5.45
	#	       
	#	  vmi = 6 -> allow to print up to 84 lignes on a A4 page!
	#				 should be verified!
	#			29.5cm - 1.1cm margin top - 1.7cm margin bottom = 26.7cm
	#			26.7cm / 2.54 cm-per-inch = 10.51 inch
	#			
	#			vmi = 11.51 inch / 84 lines-per-page * 48 = 6.57
	#			
	#	  vmi = 8 -> allow to print up to 63 lines on a A4 page!
	#				 should be verified
	#				 
	#			29.5cm - 1.1cm margin top - 1.7cm margin bottom = 26.7cm
	#			26.7cm / 2.54 cm-per-inch = 10.51 inch
    # 
	#			vmi = 11.51 inch / 63 lines-per-page * 48 = 8.007 
    #  
  
	d.vertical_motion_index( 0 ) # Disable
	d.writeln( u'This is a demo about the usage of VMI' )
	d.writeln( u'and how it can impact your print out' )
	d.writeln()
	
	d.vertical_motion_index( 6 ) # Set the value to 8 lines/inch
	                             # 84 lines-per-page
	d.writeln( u'But this better to have a proper value' )
	d.writeln( u'when printing stuff' ) 

    # Increasing the vertical motion index to put more lines in the 
    # same space.
	for vmi_value in range( vmi_start, vmi_start  + 10 ): 
		d.vertical_motion_index( vmi_value ) 
		d.writeln( u'0123456789abcdef' )
			
	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 #11
0
def print_barcode_doc( printer_socket ):
	""" Generate the mininal PCL document INCLUDING CODE39 BARCODE
	and print it on network printer.
	
	parameters:
		printer_socket : tuple (PRINTER_IP, PRINTER_PORT). On which
						 socket to print.
	"""
	
	print( 'Minimal Barcode Document 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.spacing()       # Set the default Fixed spacing
	d.pitch()         # Default 10 characters per inch
	d.horizontal_motion_index() # Set the default HMI to 0 = no horizontal motion
	d.paper_source()  # Set the default paper source to Tray + eject current page if any.
	d.symbol_set()    # Set the default symbol set (PC-850)
	
	d.writeln( u'This a demonstration document' )
	d.writeln( u'including BarCode39 generation' )
	d.writeln()
	d.writeln( u'You can read the barcode with a product like Barcode')
	d.writeln( u' Reader/Scanner Module - CCD Camera - USB Interface' ) 
	d.writeln( u'Such module is available at http://shop.mchobby.be' )
	d.writeln( u'Those module are usually configured for Qwerty Keyboards' )
	d.writeln( u' where numbers are accessible on the first row' )
	d.writeln( u'When using French keyboards, you have to press the' )
	d.writeln( u' Shift key (or Shift Lock) to activate the numeric' )
	d.writeln( u' value on the first row' )
	d.writeln( u'Surprisingly, on Linux Mint, you have to press down the' )
	d.writeln( u' RIGHT SHIFT KEY to activate numbers on the first row!' )
	d.writeln( u' The best option is certainly to reconfigure your scanner' )
	d.writeln()
	d.writeln( u'Now, enjoy the Barcode 39 reading with your scanner :-) ')
	d.writeln()
	
	bc = Barcode39( d ) # Owner must be the document	
	bc.write( u'MCHP00189' ) # Write the bar code into the document
	d.writeln()
	d.writeln( '    '+bc.barcode_message(u'MCHP00189' ) )
	d.writeln()
	
	d.pitch(15) # 15 characters per inch
	bc.write( u'GGN00030365' ) # Write the barcode in the document
	d.writeln()
	d.writeln( '    '+bc.barcode_message(u'GGN00030365' ) )
		
	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 #12
0
def print_ascii_box_doc( printer_socket ):
	""" Generate the PCL document containg an ASCII like box.

	
	parameters:
		printer_socket : tuple (PRINTER_IP, PRINTER_PORT). On which
						 socket to print.
	"""
	
	print( 'Minimal ASCII Box Document 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.symbol_set()    # Set the default symbol set (PC-850)
	d.horizontal_motion_index() # Set the default HMI to 0 = no horizontal motion
	d.paper_source()  # Set the default paper source to Tray + eject current page if any.
	d.pitch()         # Set 10 cpi size characters
	
	# Draw an ASCII like box with content (see symbol set PC-850 for details)
	# We do need to *** write binary data *** into the PclDocument
	# --- Line 1 ---
	d.write_bytes( bytes( chr(0xDA)+ chr(0xC4)*10+chr( 0xBF ) ) ) 
	d.writeln()
	# --- Line 2 --- 
	d.write_bytes( bytes( chr(0xB3) ) ) 
	d.write( u'Bordering ' )
	d.write_bytes( bytes( chr(0xB3) ) )
	d.writeln()
	# --- Line 3 ---
	d.write_bytes( bytes( chr(0xC0) + chr(0xC4)*10 + chr( 0xD9 ) ) ) 
		
	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 #13
0
def print_font_demo(printer_socket):
    """ Generate the PCL document printing a same line with various 
		font and styles.
		
		=== PAY ATTENTION === 
		The way the printer will act with various commands and print
		depend on the selected font (the font kind), the printer model
		and the parameters (not all the parameters works for a font).
		
		You will find many documentation in the "PCL 5 Printer Language
		Technical Reference Manual", Ch 8: PCL Font Selection 
		
	parameters:
		printer_socket : tuple (PRINTER_IP, PRINTER_PORT). On which
						 socket to print.
	"""

    print('Font demo')
    print('---------')
    print('Printer IP: %s\nPrinter Port: %i' % printer_socket)
    medium = PrinterSocketAdapter(printer_socket)

    d = HpPclDocument('cp850', medium)
    d.reset_printer()  # PCL to reset the printer
    d.paper_source(
    )  # Set the default paper source to Tray + eject current page if any.

    d.pitch(12)  # Set 12 cpi size characters
    d.bold()
    d.writeln(u'Here an exemple of font assignment')
    d.writeln()
    d.bold(False)

    # Follow this sequence of characteristic when assigning a font
    #  1) Symbol set      (eg: ASCII)
    #  2) Spacing         (eg: Fixed)
    #  3) Pitch           (eg: 16.66)
    #  4) Height          (eg: 8.5 point)
    #  5) Style           (eg: Upright)
    #  6) Stroke weight   (eg: Medium)
    #  7) Typeface family (eg: Line Printer)

    for typeface_name in d.PRINTER_TYPEFACE.keys():
        d.symbol_set()  # CP-850
        d.spacing()  # Set fixed
        d.pitch(16.66)
        d.height(8.5)
        d.style('upright')
        #d.style( 'italic' )

        d.stroke_weight(
            'text')  # You can use set bold for easier bold switch on/off
        d.typeface_familly(typeface_name)
        d.writeln(u'Printing abcdef.klmnopq ABC ITC.GAU with %s typeface' %
                  typeface_name)

    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 #14
0
def print_minimal_doc( printer_socket ):
	""" Generate the mininal PCL document and print it on network printer.
	
	parameters:
		printer_socket : tuple (PRINTER_IP, PRINTER_PORT). On which
						 socket to print.
	"""
	
	print( 'Minimal Hp Document 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.spacing()       # Set the default Fixed spacing
	d.horizontal_motion_index() # Set the default HMI to 0 = no horizontal motion
	d.paper_source()  # Set the default paper source to Tray + eject current page if any.
	d.symbol_set()    # Set the default symbol set (PC-850)
	
	d.writeln( u'This is my first document' )
	d.writeln( u'which accept ecute é and others' )
	d.writeln( u'Funny test' )
	d.writeln( u'' )
	
	
	# Writing in various pitch (cpi=caracter per inch)
	for cpi in d.PRINTER_CPI:
		d.pitch( cpi )
		d.writeln( u'print with cpi=%i' % cpi )
	d.writeln( u'' )
	
		
	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 #15
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 )