Where does Java get a printer’s paper sources from?

Viewed 49

We are developing a JavaFX application with a form allowing the user to print a report. In this form we show the available JavaFX printers and list the paper sources /trays of the selected printer using the following command.

printer.getPrinterAttributes().getSupportedPaperSources();

This works fine for most cases, however with some printers the names of the paper trays do not match the names according to the printer driver or the registry. I also tried the respective javax method to retrieve the trays, which returns the same tray names.

PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
        System.out.println("count of services "+services.length);
        for(int i=0;i<services.length;i++)
        {
            PrintService ps=services[i];
            
                System.out.println("Printer "+ps.getName());
                Media[] supported = (Media[]) ps.getSupportedAttributeValues(Media.class, null, null);
                for(Media m : supported) {
                     if (m instanceof MediaTray) {
                            System.out.println(m + " ID: " + m.getValue() + "\t" + m.getClass().getName());
    
                             if(m instanceof sun.print.Win32MediaTray){
                                 sun.print.Win32MediaTray  win32Tray = (sun.print.Win32MediaTray)m;
                                  System.out.println(win32Tray.winID);
                              }
    
                        }
                }       
}

Our customers are severely confused by the names of the paper trays. Sometimes Java lists them as “Top”, “Bottom”, “Middle” instead of “Tray 1”, “Tray 2” and so on. So, I tried to dig deeper and find out how Java determines the paper trays of a printer and maybe find a way to fix this issue.

Unfortunately, I couldn’t find anything about it. Does someone of you know where Java gets its information about the properties of a printer?

0 Answers
Related