Quick Tip: Printing from ColdFusion

What you need to do: print something to a Windows printer from your ColdFusion application on Linux.

How to do it: use the samba tool suite to execute a print command, sending a file to a printer.

I use a small form to collect the data that I need to print. The form results are written to a file and then the file is sent to the printer using cfexecute.

-U my_username
-W my_windows_domain_name
-c #chr(34)#print /path/to/my_file#chr(34)#”>

A few notes…

Yes, the password is just hanging out there without an argument.

The #chr(34)# is the double quotes required for the command (-c) argument.

This does not account for the printer being online or having enough ink or enough paper. My current use is for the user to print barcodes through an enterprise application that parses the data in a text file into a barcode and prints it on a sheet of labels. You might could use this to send orders from the front of a shop to the back or to print orders over the internet. However, the caveats about paper and ink should give you strong caution against such a use without careful consideration.

The smbclient program can be used to put files when FTP is not an option.


Refer to the man page for smbclient for details: http://www.samba.org/samba/docs/man/manpages-3/smbclient.1.html.

Leave a Reply