Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6921586

Java DocPrintJob always outputs printed documents to the top tray of the printer

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 6u10
    • client-libs
    • 2d
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      When trying to use javax.print.DocPrintJob to print a PostScript document on a printer that has multiple output trays (e.g., Canon iR5055/iR5065), regardless of the default selection for the output tray, the printed pages always came out of the top tray. This does not happen when using java.awt.print.PrinterJob to print a swing component. In other words, when using the java.awt.print.PrinterJob to print a swing component, the output would come out of the correct (default) printer tray as selected/pre-selected by the user.

      JUSTIFICATION :
      Our client has multiple users sharing the same printer and it is important for them to be able to designate different printer trays for different users to use.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      When using javax.print.DocPrintJob to print a document (not necessarily just PostScript file) on a printer that has multiple output trays, the default tray selected by the user (via the Windows printer setup interface) should be honored.
      ACTUAL -
      When using javax.print.DocPrintJob to print a document (not necessarily just PostScript file) on a printer that has multiple output trays, the default tray selected by the user (via the Windows printer setup interface) is ignored, instead, the printed document always came out of the top tray.

      ---------- BEGIN SOURCE ----------
      //Sample testing class for a document printing issue that does not
      //honor printer output tray selection.

      import java.awt.*;
      import javax.swing.*;
      import java.awt.print.*;
      import java.util.*;
      import javax.print.attribute.*;
      import javax.print.*;
      import java.io.*;

      public class PrintUtilities {
      public static PrintService printFile(String file, PrintService service, PrintRequestAttributeSet pras) throws FileNotFoundException, PrintException
      {
      String filename = file;
      DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
      if (pras == null)
      pras = new HashPrintRequestAttributeSet();
      if (service == null){
      PrintService printService[] =
      PrintServiceLookup.lookupPrintServices(flavor, pras);
      PrintService defaultService =
      PrintServiceLookup.lookupDefaultPrintService();

      if (defaultService == null)
      {
      System.out.println("No default service can be found!");
      if ((printService == null)|| (printService.length == 0))
      {
      System.out.println("No print service can be found!");
      return null;
      }

      else{
      defaultService = printService[0];
      }
      }
      int index = -1;

      for (int i=0; i<printService.length;i++)
      {
      if (printService[i] == defaultService){
      index = i;
      break;
      }
      }
      if (index < 0)
      defaultService = printService[0];

      //later we may need to construct this object.
      GraphicsConfiguration gc = null;
      //service = defaultService;
      service = ServiceUI.printDialog(gc,
      200, 200, printService, defaultService, flavor, pras);
      }

      if (service != null)
      {
      DocPrintJob job = service.createPrintJob();
      FileInputStream fis = new FileInputStream(filename);
      DocAttributeSet das = new HashDocAttributeSet();
      Doc doc = new SimpleDoc(fis, flavor, das);
      job.print(doc, pras);
      //Thread.sleep(1000);
      }
      return service;
      }

             //The first argument should contain the full file path to the testing
             //file.
      public static void main(String[] args) throws Exception{
      printFile(args[0], null, null);
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      There is no known workaround.

            psadhukhan Prasanta Sadhukhan
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: