7 Replies Latest reply: Sep 12, 2005 2:56 AM by 807596 RSS

    Select the printer tray using the Java Print Service with JDK 1.4.2

    807596
      Hello,

      I have got a problem with 1.4 Printing. I would like to specify the printer tray for printing on Windows platform (XP and NT4.0). I am trying to use the attribute javax.print.attribute.standard.MediaTray class (ex. MediaTray.BOTTOM).
      Howerver, I can control the printer tray if I use the PCL driver of the printer. If I user the postscript driver I am not able to control the printer tray. I can reproduce the problem with 3 different printers (HP, Lexmark and Nashuatec).

      I used the getSupportedAttributeValues to check the supported values of the Media

      Media med[] = (Media[])service.getSupportedAttributeValues(Media.class, null, null);
      for (int k=0; k<med.length; k++) {
      System.out.println("Name : " + med[k].getClass() + " - Value : " + med[k].getValue());     
      }

      With the PCL driver I have the following output and I can control the printer tray.

      Name : class javax.print.attribute.standard.MediaTray - Value : 0
      Name : class javax.print.attribute.standard.MediaTray - Value : 2
      Name : class javax.print.attribute.standard.MediaTray - Value : 4
      Name : class sun.print.Win32MediaTray - Value : 0
      Name : class sun.print.Win32MediaTray - Value : 1

      With the postscript driver I have the following output and I cannot control the printer tray

      Name : class sun.print.Win32MediaTray - Value : 5
      Name : class sun.print.Win32MediaTray - Value : 6
      Name : class sun.print.Win32MediaTray - Value : 7
      Name : class sun.print.Win32MediaTray - Value : 8
      Name : class sun.print.Win32MediaTray - Value : 9

      As I must use the postscript printer, can someone help me?

      Thanks.



        • 1. Re: Select the printer tray using the Java Print Service with JDK 1.4.2
          807596
          Hi we are experiencing problems printing to different trays.
          Can you please post your code for printing to different trays using PCL driver.
          • 2. Re: Select the printer tray using the Java Print Service with JDK 1.4.2
            807596
            For anyone watching this topic..... This maybe helpful for you. We have spent weeks trying to get the java print service to work both for Linux and Windows. We have a requirement to print to multiple trays for HP LaserJet 8150 and HP LaserJet 4000. We have also been told that printing needs to work both on Linux and Windows. We found on the HP LaserJet�s mentioned above that the printer drivers only support image file types (jpeg, gif, tiff, png, etc..) to be printed to different trays (If printing to default tray then we converted the file to PCL). The problem is that we have our content stored as xml in the database - we then use FOP to generate a PDF. Unfortunately the HP Printers do not support PDF printing. We then had to purchase 3rd party software to convert the PDF to an image file type. PNG is the file type we have chosen (PNG supports multiple page images). PNG also seems to work for Linux (postscript drivers) and windows (PCL drivers).
            • 3. Re: Select the printer tray using the Java Print Service with JDK 1.4.2
              807596
              This is a workaround that I used on the HP9050n.

              1) Go to the PrintQueue you are sending the data to. Define different custom media types for each tray. Differ the sizes by .01 or something insignificant.

              2) Under the Device Settings for the Printer Queue, define which media goes where.

              3) For the 9050 n, I had to go to the web control and define the media sizes for each tray also.

              4) Within your application, instead of searching for the tray, search for the mediaSize.

              Here's the line of code:

              float printableX = someSize;
              float printableY = someSize;
              printSet = new HashPrintRequestAttributeSet();
              mediaSizeName = MediaSize.findMedia(printableX,printableY,MediaPrintableArea.INCH);
              printSet.add(mediaSizeName);

              **make sure your printableX and printableY correspond to the media you defined.

              Since you have one media size defined per tray, the media will go the assigned tray.

              Good Luck
              • 4. Re: Select the printer tray using the Java Print Service with JDK 1.4.2
                807596
                Another suggestion: You could "create/install/setup" a printer for each tray.

                Printer1 = Tray 1
                Printer2 = Tray 2
                Printer3 = Tray3

                You would only need to print to appropriate printer. The printer setup under "windows/linux" would already point to the proper tray(the default for the printer).

                Somewhat similiar to previous answer

                Regards
                • 5. Re: Select the printer tray using the Java Print Service with JDK 1.4.2
                  807596
                  Hello,
                  Can you tell me how it's possible to selet the tray using the PCL?
                  I print on the following way:
                  PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
                  AttributeSet aset = new HashAttributeSet();
                  aset.add(new PrinterName("\\\\107208\\SBE08111", null)); // select printer
                  ......
                  Now I tried to add your code and I get the following output:
                  0: Name : class javax.print.attribute.standard.MediaSizeName - Value : 40
                  1: Name : class javax.print.attribute.standard.MediaSizeName - Value : 41
                  2: Name : class javax.print.attribute.standard.MediaSizeName - Value : 45
                  3: Name : class javax.print.attribute.standard.MediaSizeName - Value : 42
                  4: Name : class javax.print.attribute.standard.MediaSizeName - Value : 4
                  5: Name : class javax.print.attribute.standard.MediaSizeName - Value : 5
                  6: Name : class javax.print.attribute.standard.MediaSizeName - Value : 27
                  7: Name : class javax.print.attribute.standard.MediaSizeName - Value : 46
                  8: Name : class javax.print.attribute.standard.MediaSizeName - Value : 59
                  9: Name : class javax.print.attribute.standard.MediaSizeName - Value : 60
                  10: Name : class javax.print.attribute.standard.MediaSizeName - Value : 55
                  11: Name : class javax.print.attribute.standard.MediaSizeName - Value : 38
                  12: Name : class javax.print.attribute.standard.MediaSizeName - Value : 16
                  13: Name : class javax.print.attribute.standard.MediaSizeName - Value : 57
                  14: Name : class javax.print.attribute.standard.MediaTray - Value : 0
                  15: Name : class javax.print.attribute.standard.MediaTray - Value : 2
                  16: Name : class javax.print.attribute.standard.MediaTray - Value : 1
                  17: Name : class javax.print.attribute.standard.MediaTray - Value : 6
                  18: Name : class javax.print.attribute.standard.MediaTray - Value : 4
                  19: Name : class sun.print.Win32MediaTray - Value : 0
                  20: Name : class sun.print.Win32MediaTray - Value : 1

                  It's a printer with to trays, so I suppose the last two lines are important, but I'm not possible to effectively select the tray I want to print..
                  • 6. Re: Select the printer tray using the Java Print Service with JDK 1.4.2
                    807596
                    Hello, I'm still trying to select a printer tray, because I'm not allowed to install printers and select the tray on this way, I need to do this from whitin java. I'm using following code:
                    PrintService[] services3 = PrintServiceLookup.lookupPrintServices(null, null);
                    AttributeSet aset3 = new HashAttributeSet();
                    aset3.add(new PrinterName("\\\\107208\\SBE08111", null));
                    aset3.add(MediaTray.BOTTOM);
                    services3 = PrintServiceLookup.lookupPrintServices(null, aset3);
                    PrinterJob pjob = PrinterJob.getPrinterJob();
                    ....
                    with the attribute new Printer(), I can choose my printer, this works fine.. But the attribute MediaTray.BOTTOM or MediaTray.TOp doesn't change anything.. He always prints from the default tray.
                    Is there another way to solve this problem???
                    • 7. Re: Select the printer tray using the Java Print Service with JDK 1.4.2
                      807596
                      I also found that I can only print postscript to tray 1, to print to another tray I must use PNG or other image format. Not sure if this is a bug or a limitation with the print driver or the java print service. I find it strange that when querying the PrintServiceLookup.lookupPrintServices() with an AUTOSENSE (for ps) flavor and a MediaTray attribute in the attribute set, no printers will be returned. Using PNG flavor with MediaTray will return my printer as will AUTOSENSE with no tray so who knows... To get around this I tried to create a 2nd printer but even setting it to default to the MANUAL tray did not work.

                      Instead I ended up having to print my main tray pdfs as postscript and my manual tray pdfs as png. I also had to change the printer tray selection to favor 1->2->3->Manual instead of Manual.