This discussion is archived
2 Replies Latest reply: Oct 29, 2012 7:04 PM by EJP RSS

Need help with Printing using javax.print.*

418285 Newbie
Currently Being Moderated
Hi,

Using version 1.6 and we have different Printers Canon/Xerox/HP, mostly with 4 input trays. Trays 3,4 have the same size and type of paper.

I'm writing a program that needs to automatically switch between trays depending on certain parameters. I'm having a REALLY hard time figuring out how to get the printer to switch trays.

I've been able to assign the MediaTray.BOTTOM, etc., attributes to the PrintRequestAttributeSet. However, it's having no effect on which tray the printer is using.

I ran this code:

if (service.isAttributeValueSupported(MediaTray.TOP, null, null)) {
          System.out.println("Yes, Media tray TOP supported");
     } else {
          System.out.println("NO, Media tray TOP is NOT supported");
     }

Which results is a "NO, Media tray TOP is NOT supported" for every value of MediaTray. However, when I run this code:

          Object o = service.getSupportedAttributeValues(Media.class, flavor, null);
          if (o != null && o.getClass().isArray())
          {
               for (Media media : (Media[]) o)
               {
                    System.out.println(media + "\t\t\t\t\t ID: " + media.getValue() + "\t\t\t" + media.getClass().getName()+ "\t\t NAME:" + media.getName()+ "\t\t CLASS:" + media.getClass());
               }
          }

I get the following output:

**************************************************

Nope, Media tray TOP is NOT supported

na-letter ID: 40 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
na-legal ID: 41 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
invoice ID: 45 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
executive ID: 42 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
folio ID: 46 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
b ID: 51 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
na-9x11-envelope ID: 66 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
na-5x7 ID: 71 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
na-8x10 ID: 72 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
Postcard (4.5 x 6") ID: 1 NAME:media CLASS:class sun.print.Win32MediaSize
5.5 x 7" ID: 2 NAME:media CLASS:class sun.print.Win32MediaSize
iso-a4 ID: 4 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
iso-a3 ID: 3 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
iso-a5 ID: 5 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
jis-b4 ID: 26 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
jis-b5 ID: 27 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
iso-a6 ID: 6 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
jis-b6 ID: 28 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
A4 Oversized (223 x 297 mm) ID: 3 NAME:media CLASS:class sun.print.Win32MediaSize
na-number-9-envelope ID: 59 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
na-number-10-envelope ID: 60 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
monarch-envelope ID: 57 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
iso-designated-long ID: 55 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
iso-c5      ID: 38 NAME:media CLASS:class javax.print.attribute.standard.MediaSizeName
Custom      ID: 4 NAME:media CLASS:class sun.print.Win32MediaSize
Form-Source ID: 5 NAME:media CLASS:class sun.print.Win32MediaTray
manual      ID: 4 NAME:media CLASS:class javax.print.attribute.standard.MediaTray
Tray 4      ID: 6 NAME:media CLASS:class sun.print.Win32MediaTray
Tray 3      ID: 7 NAME:media CLASS:class sun.print.Win32MediaTray
Tray 2      ID: 8 NAME:media CLASS:class sun.print.Win32MediaTray
Tray 1      ID: 9 NAME:media CLASS:class sun.print.Win32MediaTray

**************************************************

What this is telling me is that passing the value of "TOP" (or whatever MediaTray value I use) for "media" isn't supported by this printer. I'm sure what I need to be passing is the values listed above, but I can't figure out how to do that. I don't know if I need to somehow make a custom Media/MediaTray class or what.

Appreciate any guidance/help

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points