I have had a fair amount of trouble with odd behaviors and bugs in printing with Java. The time I have had to spend at work to eliminate troublesome behavior in a heavily used Java application (both before customers see the problem, and after customers report problems) … is embarrassing.
After getting stuck on the latest problem, I finally built a “PrintExplorer” test program. The sources are up on Kenai, and on my website. In both cases the sources are in a Mercurial repository, and I “push” changes to both (one of the nice features of Mercurial). The project was built using NetBeans 6.7, and you can download the built PrintExplorer.jar file.
Run as usual:
java -jar PrintExplorer.jar
(On Windows you can just double-click the JAR file.)
I filed two reports (so far, with review ids: 1660182 and 1660234) with bugs.sun.com, though for all I know that may be a black hole (or not … I have no idea). With the OpenJDK and JDK7 work there may be better places to report/record this … I do not know. (If you know a better path, please let me know.)
Found so far:
- PrinterJob.getPageDialog() makes invalid change to page size. (log)
- Toolkit.getPrintJob() changes JobAttributes.getPrinter() to default(?) printer. (log)
- Quarter-sized pages sometimes printed on an HP DeskJet 5550 on Windows 7. (log)
I am sure there are more. :/
Note that PrintExplorer always generates a log file. The log file contains the parameter values and print operations performed. (You need to be acquainted with Java Printing, otherwise the test program will be entirely obscure.) If you can reproduce a problem, then you can see in the log file exactly what you did, and what was returned. (Useful when you lost track of the exact sequence of steps.) When you send a log file, anyone can verify the exact sequence of steps you followed (a mistake in the problem description can be caught).
At this point the DocPrinterJob works for an empty Doc and a Pageable Doc, but not for a Reader Doc. (Unclear if the last is my bug, or a Java bug.)