Printer services Not found?

后端 未结 1 416
无人共我
无人共我 2020-12-22 08:06

When i Debug this program the services array is empty??

 import java.io.FileInputStream;
    import java.io.FileNotFoundException;

    import javax.print.D         


        
相关标签:
1条回答
  • 2020-12-22 08:33

    This is because there was no PrintService found corresponding to the specified DocFlavor and Attribute Set. It may be hard to find a printer which supports PostScript unless your printer hardware is pretty up to date. You can check what all DocFlavors are supported like this:

    DocFlavor[] docFalvor = prnSvc.getSupportedDocFlavors();
            for (int i = 0; i < docFalvor.length; i++) {
                System.out.println(docFalvor[i].getMimeType());
            }
    

    For locating a specific Print Service you can do something like this:

    PrintService prnSvc = null;
    
        /* locate a print service that can handle it */
        PrintService[] pservices =
                PrintServiceLookup.lookupPrintServices(null, null);
        if (pservices.length > 0) {
            int ii=0;
            while(ii < pservices.length)
            {
                System.out.println("Named Printer found: "+pservices[ii].getName());
                if (pservices[ii].getName().endsWith("YourPrinterName")) {
                    prnSvc = pservices[ii];
                    System.out.println("Named Printer selected: " + pservices[ii].getName() + "*");
                    break;
                }
              ii++;
            }
    
    0 讨论(0)
提交回复
热议问题