This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,889,769 Users
  • 2,269,775 Discussions


Unable to specify printer for print jobs in Java7 for OSX

956347 Member Posts: 1
edited Jun 10, 2013 4:35PM in Abstract Window Toolkit (AWT)
Hi, I'm developing a simple software that would monitor a folder for new documents and print them automatically. Monitoring the folder was the easy part with WatchService in Java7, but I'm running into problems with printing. Namely, I'm using java.awt.print.PrinterJob to print the document, but the print job is always sent to the default printer, instead of the printer that was specified.

PrinterJob pPrinterJob = PrinterJob.getPrinterJob();
PrintService[] psArr = PrinterJob.lookupPrintServices();
for (PrintService ps : psArr) {
if (ps.getName().equalsIgnoreCase(specifiedPrinterName)) {
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
//specify print attributes....

The code looks simple enough, and calling getPrinterService() returns the intended printer after specifying it using setPrinterService(). However, regardless of the printer specified, the print job is still sent to the default printer. Tried on both Java 7 Update 4 and Update 6 for OSX with the same result.

Update: Got my hands on a Win XP machine and tried out the same piece of code using Java 7 Update 6 for Windows. Guess what, the print job was sent to the specified printer! I'm pretty sure this is an OSX specific issue now. Has anyone come across this issue previously?


  • 1013822
    1013822 Member Posts: 1


    I have the exact same problem on OS X 10.8.2 with Java 1.7.0 Update 21.

    When I call PrintServiceLookup.lookupPrintServices(null, null) I get three distinct printers, but no matter which of the three I specify, the print job is sent to the default printer.

    The code works as expected when tested on Windows and Linux machines.

    Any help is appreciated!

This discussion has been closed.