1 Reply Latest reply on Jun 10, 2013 8:35 PM by 7ea00665-31d3-46f3-929e-a5bf2430909a

    Unable to specify printer for print jobs in Java7 for OSX

      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?