How to print a PDF from a gateway script

Ok, I will look into it. Can you do it from a tag change script?

If you can do it at all, I don’t see why it wouldn’t work from a tag change script.

As an alternative option, many newer printers support HTTP REST methods and other types of printing beyond a standard windows queue. I think most would agree dealing with printers and drivers, especially in windows is absolutely miserable.

Others in the forum have done label printing through simple system.net.httpClient calls. Obviously this depends on your printer models and if they support it, but dig into the manual and many will have an HTTP print option where you can POST the file in a simple web call.

Another option is to use a print service in the middle to automate your printers. We have enterprise label software, NiceLabel, in our facility which is great for labeling, but they also have a nice automation engine where we have a layer where we can automate label printing and some basic document printing using just about any type of TCP, HTTP, File, DB, style triggers to execute some type of printing. Were actually in the process of swiching all our shipment labeling to use Ignition with HTTP calls to NiceLabel to handle all the printing. It keeps Ignition from having to deal with the mess that is printing and let a more dedicated software handle it.

3 Likes

Lets back tract. Can I use a tag change script to print a PDF Viewer on a window?

Tag change script = gateway scope
PDF viewer on a window = client scope

You can’t reach the window from the tag change script, the scripts run on different machines.

What you can do however, is bind the tag change to a property, and execute a script on property change. But I’ll advise you to try some simple printing first: make a button and print by pressing the button. That way it will be easier to see the errors. If you got that working, you can put that button code on some other trigger.

does anyone know the script for a mouse click to print a PDF Viewer. I can’t find it in the manual.

It isn’t a mouse click, it is a method, the .print() method stated above. Per the component documentation.

I tried this… but I get a error

Traceback (most recent call last):

File “event:mouseClicked”, line 3, in

TypeError: print(): expected 0-1 args; got 2

pdf = event.source.parent.getComponent("PDF Viewer")
pdf.print("\\ami-print\PLC-Office", 0)

The only argument shown in the manual for the .print() function is a showDialog argument. I’m assuming your “\ami-print\PLC-Office” was trying to specify a printer. When the function doesn’t give you a way to specify one, you can’t just add it in. The print function will use your default printer if you do .print(0). If you do .print() or .print(1) it will give a dialog for the user to select a printer. Those are the only parameter options you have for the print function.

When your working on this, remember that the manual is your friend. There is a component section that talks about each component and describes any script functions they have. Knowing what functions are available for a component your using and what parameters they can take can make life easier.

1 Like

Anyone have any ideas?

It seems you’ll have to figure how to use the Java Print Services infrastructure.

I got it figured out with tech supports help, I had to use a third party software to print a pdf from a command line.

Had to put this on the gateway computer. http://www.columbia.edu/~em36/pdftoprinter.html

Here is the test script that works after you load the software on the gateway computer.

if system.tag.read ("[default]Test123").value ==1:
	#logger = system.util.getLogger("Gateway Timer Printer Script")
	#logger.info("script started")
	system.util.execute( ['C:\\PDFtoPrinter\\PDFtoPrinter.exe', "\\\\amifile\\Departments\\Work Instructions and Procedures\\Forms\\QD 717 Daily Furnace baghouse pm.PDF", "\\\\ami-print\\PLC-Office"])
	#logger.info("Script ended")