hertzon
hertzon

Reputation: 89

Print problem with pos printer CUP server Ubuntu 16

I installed a cups server on Ubuntu 16, after installed a POS printer, after tested test page and lpr command line command and it works ok; in java using PrintJob, java find the printer, but no printer anything....

some ideas to fix this problem??

Upvotes: 0

Views: 103

Answers (1)

gonzaloan
gonzaloan

Reputation: 371

I had the same problem some time ago, i did this, maybe could help you. Let me know.

public static boolean imprimirDocto(String documentPath, String printerName) {
        File f = new File(documentPath);
        try {
            PDDocument doc = PDDocument.load(f);

            PrinterJob pj = PrinterJob.getPrinterJob();

            PrintService[] ps = PrintServiceLookup.lookupPrintServices(null, null);
            PrintService printService = null;
            if (ps.length > 0) {
                //This searchs for all the printers, and looks for the 'printerName'
                for (int i = 0; i < ps.length; i++) {
                    System.out.println("Printer name: " + ps[i]);
                    if (ps[i].getName().toLowerCase().contains(printerName.toLowerCase())
                            || ps[i].getName().contains(printerName)) {

                        printService = ps[i];

                        System.out.println("Setting the printer...");
                        pj.setPrintService(printService);
                        i = ps.length;
                    }
                }

                pj.setPageable(new PDFPageable(doc));
                pj.print();

                return true;

            } else {
                return false;
            }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }
    }

Upvotes: 1

Related Questions