public static boolean isPrinterAvailable(String printerName) {
        DocFlavor myFormat = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

        PrintService[] printers = PrintServiceLookup.lookupPrintServices(myFormat, aset);

        for (PrintService printService : printers) {
            if (printService.getName().equals(printerName)) {
                Attribute attribute =
                        printService.getAttribute(PrinterIsAcceptingJobs.class);

                if (attribute.toString().equals("accepting-jobs")) {
                    return true;
                }
            }
        }

        return false;
    }