Printing to a local client printer in a Vision client

I had this done up yesterday, but then got yanked to go to to one of our sister plants. :roll_eyes:

I prefer looking up the printer by name, because somehow, somewhere, someone will add another printer and make it the default.

from javax.print import DocFlavor, SimpleDoc, PrintServiceLookup
from java.io import ByteArrayInputStream

# Get all available printers
printServices = PrintServiceLookup.lookupPrintServices(None, None)

# Initialize print service variable
printService = None

# Check for specific printer name
for service in printServices:
	if service.name == 'Label Printer': # Replace with your own printer name.
		printService = service

# Send message if the printer exists
if printService is not None:
	fgPartNum = '4CJ9196WA65'
	serialNum = 74889000
	strMessage = '^XA^BY3,3,167^FT040,280,^B3N,N,,N,N^FDS{sn}^FS^FT0060,080^A0N,40,45^FDS{sn}    {pn}^FS^PQ1,0,0,N^XZ'.format(sn=serialNum, pn=fgPartNum)
	
	# Create an input stream
	messageStream = ByteArrayInputStream(strMessage)
	flavor = DocFlavor.INPUT_STREAM.AUTOSENSE
	doc = SimpleDoc(messageStream, flavor, None)
	
	job = printService.createPrintJob()
	job.print(doc, None)
	messageStream.close()
	
else:
	print 'Printer Not Found'
4 Likes