Saturday, March 28, 2020

Function Java Cashdrawer & Direct Print with web

Function Untuk mencetak langsung ke printer dan langsung membuka cashdrawer box kasir
 

 public void f_cashdrawer(String printer_name) {     
        // sesuaikan dengan tipe printer termal
        byte[] open = {27, 112, 0, 25, (byte)251};
        String printer = PrinterName;
        PrintServiceAttributeSet printserviceattributeset = new HashPrintServiceAttributeSet();
        printserviceattributeset.add(new PrinterName(printer,null));
        PrintService[] printservice = PrintServiceLookup.lookupPrintServices(null, printserviceattributeset);
        if(printservice.length!=1){
            System.out.println("Printer not found");
        }
        PrintService pservice = printservice[0];
        DocPrintJob job = pservice.createPrintJob();
        DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
        Doc doc = new SimpleDoc(open,flavor,null);
        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        try {
            job.print(doc, aset);
        } catch (PrintException ex) {
            System.out.println(ex.getMessage());
        }
    }

public void f_print(String v_filepdf, String v_nama_printer) throws FileNotFoundException, IOException {             
        DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
        PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null);
        FileInputStream psStream = null;
        try {
             //   misal :   psStream = new FileInputStream("d:\\test.pdf");
            psStream = new FileInputStream(v_filepdf);
            } catch (FileNotFoundException ffne) {
              ffne.printStackTrace();
            }
        if (psStream == null) {
            return;
        }     
        if (services.length > 0)
        {
            PrintService myService = null;
            for(PrintService service : services) {
                System.out.println(service.getName());
                if(service.getName().contains(v_nama_printer)) {
                // misal : if(service.getName().contains("Epson AL-2600")) {
                    myService = service;
                    break;
                }
            }
            DocPrintJob printJob = myService.createPrintJob();
            Doc document = new SimpleDoc(psStream, flavor, null);
            try {
                printJob.print(document, null);
            } catch (PrintException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        else
        {
            System.out.println("No PDF printer available.");
        }     
       // cashdrawerOpen(v_nama_printer);
    }

Memunculkan Simbol & Emoji Pada OS Mac

  Memunculkan Simbol & Emoji  1. Buka aplikasi Pages / Notes pada Macbook. 2. Klik pada Menubar Edit --> Pilih Emoji and Symbols a...