Command line PDF printing
Wednesday, March 30th, 2005Another day, another problem….
We have an automated printing system for invoices that downloads an automatically generated PDF invoice from our production server to one of our office Linux servers and then prints it out before deleting it.
Today the toner cartrige ran out on the printer and so invoices were starting to get backed up in the print queue. It could easily have been a few days before we could get the printer up and running so I thought about the alternatives
- Get them and print them manually on our other colour laser printer - really can´t be bothered
- Let them back up till it´s fixed - not the best of ideas
- Get them automatically printing on the other printer
So I decided to try and get them going on the other printer (it could be useful in case this happens again). Only problem is that this printer is a USB device shared on a Windoze 2000 server. I guessed that trying to get the linux server printing to the windows share would be a knightmare so I went with the option of getting windows to do the printing.
The Linux server is set up with a Samba share so all I needed to do is print the PDFs. I´d heard somewhere that you can do command line printing with Acrobat Reader so I did some reseach to find out how. After three hours of browsing the internet I found out a few things…
- Newer version of the Reader will print from the command line but the Reader window won´t close after printing the document and so doesn´t lend well to batch or automated printing.
- Older versions (think 4.0 or below) will do it but I had problems with some of the images being in black and white instead of colour.
- You have to pay for a solution that actually works…
So I went back to the drawing board. Next option, try to hook up the Linux server to the Windows printer. After a bit of searching, turns out it´s bloody easy! Since I have Samba installed, I also have the smbclient installed and you can use this to print a .ps (converted with Ghostscript from a pdf) with a one line command!
Put this in a script (or in my case a php file so I can do other things at the same time) and you´re good to go my friends.
Windows is easy, Linux is complecated… Bullshit!