Joined: Sun Oct 19, 2008 3:53 pm Posts: 229 Has thanked: 0 time Have thanks: 0 time
I spent most of the day yesterday trying to print a PDF file from a Java application. I finally succeeded, but the solution may not work. So here I am.
The requirements are that it cannot have user interaction. The target systems are locked down terminals that are imaged and set up in warehouse with specific settings, so I can reasonably assume that default printer settings will work. Preferably, the solution would require neither spending money (like most companies it is bad enough ordering office supplies let alone software licenses) nor using GPL software (BSD/Apache are fine though). Ideally this would be a pure Java solution that is cross platform, unlike the current solution of shell scripts that break in Windows and half the Linux distributions.
I found PDFBox - http://www.pdfbox.org/ - but I cannot get it to work no matter how hard I try. Usually I get an exception while printing stating "operation not implemented" even on simple PDFs. Sometimes PDFs print, Windows says it sent a job to the printer, but the job has "N/A" pages and nothing prints.
Next I tried setting up command line utilities and scripts against my better judgment to convert PDF files on the fly (or preconvert them, doesn't matter) and send PostScript files directly to the printer. According to Java, there are no printers attached to my computer (there are four network printers) that support either PDF or PostScript flavors. If I send the job anyway (it is a high end Ricoh color laser printer that supports PDF and PostScript natively according to Ricoh's web site) then Java throws an exception about an invalid flavor. Oddly enough, the scripting side of the equation works. I can use "pdftops input.pdf -" and pipe its STDOUT into an InputStream in my application and then (try to) send it off to the printer.
Finally I downloaded a trial of jPDFPrint - http://www.qoppa.com/jprindex.html - and this works, but costs money, and like I said my company is cheap. It does pop up a print options dialog but I am sure I can get rid of it, but 6:00 PM on a Friday is time to declare victory and go home for the weekend.
I will admit that printing is one part of software development I do not have much experience with. Is there anything I am missing here, any libraries that are known to work? Does anyone have any recommendations?