Package jpos

Examples of jpos.POSPrinter


        }
    }

    public void printReceipt(PosTransaction trans, boolean printStoreCopy) {
        Debug.log("Print Receipt Requested : " + trans.getTransactionId(), module);
        POSPrinter printer = (POSPrinter) control;
        this.lastTransaction = trans;

        try {
            if (!checkState(printer)) {
                return;
View Full Code Here


        if (sDeviceDrawerName != null && !sDeviceDrawerName.equals("")) {
            m_sName += " - " + sDeviceDrawerName;
        }
              
        try {      
            m_printer = new POSPrinter();
            m_printer.open(sDevicePrinterName);
            m_printer.claim(10000);
            m_printer.setDeviceEnabled(true);
            m_printer.setMapMode(POSPrinterConst.PTR_MM_METRIC)// unit = 1/100 mm - i.e. 1 cm = 10 mm = 10 * 100 units
        } catch (JposException e) {
View Full Code Here

        }
    }

    public void printReceipt(PosTransaction trans, boolean printStoreCopy) {
        Debug.logInfo("Print Receipt Requested : " + trans.getTransactionId(), module);
        POSPrinter printer = (POSPrinter) control;
        this.lastTransaction = trans;

        try {
            if (!checkState(printer)) {
                return;
View Full Code Here

        }
    }

    public void printReceipt(PosTransaction trans, boolean printStoreCopy) {
        Debug.log("Print Receipt Requested : " + trans.getTransactionId(), module);
        POSPrinter printer = (POSPrinter) control;
        this.lastTransaction = trans;

        try {
            if (!checkState(printer)) {
                return;
View Full Code Here

        if (sDeviceDrawerName != null && !sDeviceDrawerName.equals("")) {
            m_sName += " - " + sDeviceDrawerName;
        }
              
        try {      
            m_printer = new POSPrinter();
            m_printer.open(sDevicePrinterName);
            m_printer.claim(10000);
            m_printer.setDeviceEnabled(true);
            m_printer.setMapMode(POSPrinterConst.PTR_MM_METRIC)// unit = 1/100 mm - i.e. 1 cm = 10 mm = 10 * 100 units
        } catch (JposException e) {
View Full Code Here

        }
    }

    public void printReceipt(PosTransaction trans, boolean printStoreCopy) {
        Debug.log("Print Receipt Requested : " + trans.getTransactionId(), module);
        POSPrinter printer = (POSPrinter) control;
        this.lastTransaction = trans;

        try {
            if (!checkState(printer)) {
                return;
View Full Code Here

        }
    }

    public void printReceipt(PosTransaction trans, boolean printStoreCopy) {
        Debug.log("Print Receipt Requested : " + trans.getTransactionId(), module);
        POSPrinter printer = (POSPrinter) control;
        this.lastTransaction = trans;

        try {
            if (!checkState(printer)) {
                return;
View Full Code Here

        }
    }

    public static void main(String args[]) throws Exception {
       
        POSPrinter printer = new POSPrinter();
          try
        {
            // open the printer object according to the entry names defined in jpos.xml
            //printer.open("TSP700-linux-usb");               // TSP700 printer - linux - usb
            //printer.open("TSP700-linux-serial");            // TSP700 printer - linux - serial
            //printer.open("TSP700-linux-parallel");          // TSP700 printer - linux - parallel
           
            //printer.open("TSP700-windows-usb");             // TSP700 printer - windows - usb
            //printer.open("TSP700-windows-serial");          // TSP700 printer - windows - serial
           // printer.open("TSP700-windows-parallel");        // TSP700 printer - windows - parallel
            printer.open("SP500-tearbar-windows-parallel");        // TSP700 printer - windows - parallel
            //printer.open("TSP700-mac-usb");                 // TSP700 printer - mac - usb

            //printer.open("TSP700-ethernet");                  // TSP700 printer - ethernet
           
            // claim exclsive usage of the printer object
            printer.claim(1);
           
            // enable the device for input and output
            printer.setDeviceEnabled(true);
           
            // set map mode to metric - all dimensions specified in 1/100mm units
            printer.setMapMode(POSPrinterConst.PTR_MM_METRIC)// unit = 1/100 mm - i.e. 1 cm = 10 mm = 10 * 100 units
           
            do
            {
                // poll for printer status
                //   a javax.swing based application would be best to both poll for status
                //   AND register for asynchronous StatusUpdateEvent notification
                //   see the JavaPOS specification for details on this
               
                // check if the cover is open
                if (printer.getCoverOpen() == true)
                {
                    System.out.println("printer.getCoverOpen() == true");
                   
                    // cover open so do not attempt printing
                    break;
                }
               
                // check if the printer is out of paper
                if (printer.getRecEmpty() == true)
                {
                    System.out.println("printer.getRecEmpty() == true");
                   
                    // the printer is out of paper so do not attempt printing
                    break;
                }
               
                // being a transaction
                //   transaction mode causes all output to be buffered
                //   once transaction mode is terminated, the buffered data is
                //   outputted to the printer in one shot - increased reliability
                printer.transactionPrint(POSPrinterConst.PTR_S_RECEIPT, POSPrinterConst.PTR_TP_TRANSACTION);
               
                if (printer.getCapRecBitmap() == true)
                {
                    // print an image file
                    try
                    {
                        printer.printBitmap(POSPrinterConst.PTR_S_RECEIPT, "star.gif", POSPrinterConst.PTR_BM_ASIS, POSPrinterConst.PTR_BM_CENTER);
                    }
                    catch (JposException e)
                    {
                        if (e.getErrorCode () != JposConst.JPOS_E_NOEXIST)
                        {
                            // error other than file not exist - propogate it
                            throw e;
                        }
                       
                        // image file not found - ignore this error & proceed
                    }
                }
               
                // call printNormal repeatedly to generate out receipt
                //   the following JavaPOS-POSPrinter control code sequences are used here
                //   ESC + "|cA"          -> center alignment
                //   ESC + "|4C"          -> double high double wide character printing
                //   ESC + "|bC"          -> bold character printing
                //   ESC + "|uC"          -> underline character printing
                //   ESC + "|rA"          -> right alignment
               
              
                               
                if (printer.getCapRecBarCode() == true)
                {
                    // print a Code 3 of 9 barcode with the data "123456789012" encoded
                    //   the 10 * 100, 60 * 100 parameters below specify the barcode's height and width
                    //   in the metric map mode (1cm tall, 6cm wide)
                    printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT, "123456789012", POSPrinterConst.PTR_BCS_Code39, 10 * 100, 60 * 100, POSPrinterConst.PTR_BC_CENTER, POSPrinterConst.PTR_BC_TEXT_BELOW);
                }
               
               // printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|cA" + ESC + "|4C" + ESC + "|bC" + "Thank you" + LF);

                // the ESC + "|100fP" control code causes the printer to execute a paper cut
                //   after feeding to the cutter position
               // printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|100fP");

                // terminate the transaction causing all of the above buffered data to be sent to the printer
                printer.transactionPrint(POSPrinterConst.PTR_S_RECEIPT, POSPrinterConst.PTR_TP_NORMAL);
               
                // exit our printing loop
         
     final JFrame frame = new JFrame("Printing");
     frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

     Container contentPane = frame.getContentPane();

     final Component printIt = new MyComponent();
     contentPane.add(printIt, BorderLayout.CENTER);
     contentPane.setBackground(Color.WHITE);
     JButton button = new JButton("Print");
     contentPane.add(button, BorderLayout.SOUTH);

     ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
            PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
            DocPrintJob job = printService.createPrintJob();
            PrintJobListener pjlistener = new PrintJobAdapter() {
                public void printDataTransferCompleted(PrintJobEvent e) {
                    System.out.println("Good Bye");
                    System.exit(0);
                }
            };
            job.addPrintJobListener(pjlistener);
            PrintRequestAttributeSet pras =
                new HashPrintRequestAttributeSet();

            DocAttributeSet das = new HashDocAttributeSet();
            Doc doc = new SimpleDoc(printIt, flavor, das);
            try {  
                    job.print(doc, pras);
                } catch (PrintException pe) {
                    pe.printStackTrace();
                }
       }
     };
     button.addActionListener(listener);

     frame.setSize(200, 350);
     frame.setVisible(true);
  
              } while (false);
        }
        catch(JposException e)
        {
            // display any errors that come up
            e.printStackTrace();
        }
        finally
        {
            // close the printer object
            try
            {
                printer.close();
            }
            catch (Exception e) {}
        }
       
        System.out.println("StarReceiptTest finished.");
View Full Code Here

       
        String ESC    = ((char) 0x1b) + "";
        String LF     = ((char) 0x0a) + "";
       
        // instantiate a new jpos.POSPrinter object
        POSPrinter printer = new POSPrinter();
       
        try
        {
            // open the printer object according to the entry names defined in jpos.xml
            //printer.open("TSP700-linux-usb");               // TSP700 printer - linux - usb
            //printer.open("TSP700-linux-serial");            // TSP700 printer - linux - serial
            //printer.open("TSP700-linux-parallel");          // TSP700 printer - linux - parallel
           
            //printer.open("TSP700-windows-usb");             // TSP700 printer - windows - usb
            //printer.open("TSP700-windows-serial");          // TSP700 printer - windows - serial
            //printer.open("TSP700-windows-parallel");        // TSP700 printer - windows - parallel
           
            printer.open("TSP700-mac-usb");                 // TSP700 printer - mac - usb

            //printer.open("TSP700-ethernet");                  // TSP700 printer - ethernet
           
            // claim exclsive usage of the printer object
            printer.claim(1);
           
            // enable the device for input and output
            printer.setDeviceEnabled(true);
           
            // set map mode to metric - all dimensions specified in 1/100mm units
            printer.setMapMode(POSPrinterConst.PTR_MM_METRIC)// unit = 1/100 mm - i.e. 1 cm = 10 mm = 10 * 100 units
           
            do
            {
                // poll for printer status
                //   a javax.swing based application would be best to both poll for status
                //   AND register for asynchronous StatusUpdateEvent notification
                //   see the JavaPOS specification for details on this
               
                // check if the cover is open
                if (printer.getCoverOpen() == true)
                {
                    System.out.println("printer.getCoverOpen() == true");
                   
                    // cover open so do not attempt printing
                    break;
                }
               
                // check if the printer is out of paper
                if (printer.getRecEmpty() == true)
                {
                    System.out.println("printer.getRecEmpty() == true");
                   
                    // the printer is out of paper so do not attempt printing
                    break;
                }
               
                // being a transaction
                //   transaction mode causes all output to be buffered
                //   once transaction mode is terminated, the buffered data is
                //   outputted to the printer in one shot - increased reliability
                printer.transactionPrint(POSPrinterConst.PTR_S_RECEIPT, POSPrinterConst.PTR_TP_TRANSACTION);
               
                if (printer.getCapRecBitmap() == true)
                {
                    // try using STAR_DIO_PRINT_JAVA_AWT_IMAGE DirectIO
                    // same as standard printBitmap method but operates on an im-memory image
                   
                    // parameter format
                    int command = StarVendorConst.STAR_DIO_PRINT_JAVA_AWT_IMAGE;
                   
                    int data[] = new int[3];
                    data[0]    = POSPrinterConst.PTR_S_RECEIPT; // station
                    data[1]    = POSPrinterConst.PTR_BM_ASIS;   // width in map mode
                    data[2]    = POSPrinterConst.PTR_BM_CENTER; // alignment
                   
                    java.awt.Image image = new javax.swing.ImageIcon("star.gif").getImage();
                   
                    printer.directIO(command, data, image);
                }

                // the ESC + "|100fP" control code causes the printer to execute a paper cut
                //   after feeding to the cutter position
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|100fP");

                // terminate the transaction causing all of the above buffered data to be sent to the printer
                printer.transactionPrint(POSPrinterConst.PTR_S_RECEIPT, POSPrinterConst.PTR_TP_NORMAL);
               
                // exit our printing loop
            } while (false);
        }
        catch(JposException e)
        {
            // display any errors that come up
            e.printStackTrace();
        }
        finally
        {
            // close the printer object
            try
            {
                printer.close();
            }
            catch (Exception e) {}
        }
       
        System.out.println("StarReceiptTest finished.");
View Full Code Here

        String ESC    = ((char) 0x1b) + "";
        String LF     = ((char) 0x0a) + "";
        String SPACES = "                                                                      ";
       
        // instantiate a new jpos.POSPrinter object
        POSPrinter printer = new POSPrinter();
       
        try
        {
            // open the printer object according to the entry names defined in jpos.xml
            //printer.open("TSP700-linux-usb");               // TSP700 printer - linux - usb
            //printer.open("TSP700-linux-serial");            // TSP700 printer - linux - serial
            //printer.open("TSP700-linux-parallel");          // TSP700 printer - linux - parallel
           
            //printer.open("TSP700-windows-usb");             // TSP700 printer - windows - usb
            //printer.open("TSP700-windows-serial");          // TSP700 printer - windows - serial
            printer.open("TSP700-windows-parallel");        // TSP700 printer - windows - parallel
           
            //printer.open("TSP700-mac-usb");                 // TSP700 printer - mac - usb

            //printer.open("TSP700-ethernet");                  // TSP700 printer - ethernet
           
            // claim exclsive usage of the printer object
            printer.claim(1);
           
            // enable the device for input and output
            printer.setDeviceEnabled(true);
           
            // set map mode to metric - all dimensions specified in 1/100mm units
            printer.setMapMode(POSPrinterConst.PTR_MM_METRIC)// unit = 1/100 mm - i.e. 1 cm = 10 mm = 10 * 100 units
           
            do
            {
                // poll for printer status
                //   a javax.swing based application would be best to both poll for status
                //   AND register for asynchronous StatusUpdateEvent notification
                //   see the JavaPOS specification for details on this
               
                // check if the cover is open
                if (printer.getCoverOpen() == true)
                {
                    System.out.println("printer.getCoverOpen() == true");
                   
                    // cover open so do not attempt printing
                    break;
                }
               
                // check if the printer is out of paper
                if (printer.getRecEmpty() == true)
                {
                    System.out.println("printer.getRecEmpty() == true");
                   
                    // the printer is out of paper so do not attempt printing
                    break;
                }
               
                // being a transaction
                //   transaction mode causes all output to be buffered
                //   once transaction mode is terminated, the buffered data is
                //   outputted to the printer in one shot - increased reliability
                printer.transactionPrint(POSPrinterConst.PTR_S_RECEIPT, POSPrinterConst.PTR_TP_TRANSACTION);
               
                if (printer.getCapRecBitmap() == true)
                {
                    // print an image file
                    try
                    {
                        printer.printBitmap(POSPrinterConst.PTR_S_RECEIPT, "star.gif", POSPrinterConst.PTR_BM_ASIS, POSPrinterConst.PTR_BM_CENTER);
                    }
                    catch (JposException e)
                    {
                        if (e.getErrorCode () != JposConst.JPOS_E_NOEXIST)
                        {
                            // error other than file not exist - propogate it
                            throw e;
                        }
                       
                        // image file not found - ignore this error & proceed
                    }
                }
               
                // call printNormal repeatedly to generate out receipt
                //   the following JavaPOS-POSPrinter control code sequences are used here
                //   ESC + "|cA"          -> center alignment
                //   ESC + "|4C"          -> double high double wide character printing
                //   ESC + "|bC"          -> bold character printing
                //   ESC + "|uC"          -> underline character printing
                //   ESC + "|rA"          -> right alignment
               
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|cA" + ESC + "|4C" + ESC + "|bC" + "Star Grocer"     + LF);
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|cA" + ESC + "|bC" +               "Shizuoka, Japan" + LF);
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|cA" + ESC + "|bC" +               "054-555-5555"    + LF);

                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|uC" + "Qnty Unit Tx Description" + SPACES.substring(0, printer.getRecLineChars() - "Qnty Unit Tx Description".length()) + LF);
               
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               "   1  830    Soba Noodles"        + LF);
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               "   1  180    Daikon Radish"       + LF);
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               "   1  350    Shouyu Soy Sauce"    + LF);
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               "   1   80    Negi Green Onions"   + LF);
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               "   1  100    Wasabi Horse Radish" + LF);
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               "   2  200 Tx Hashi Chop Sticks"   + LF);
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, LF);
               
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               ESC + "|rA" +               "Subtotal:  2160" + LF);
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               ESC + "|rA" +               "Tax:         24" + LF);
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               ESC + "|rA" + ESC + "|bC" + "Total:     2184" + LF);
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               ESC + "|rA" +               "Tender:    2200" + LF);
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               ESC + "|rA" + ESC + "|bC" + "Change:      16" + LF);
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, LF);
                               
                if (printer.getCapRecBarCode() == true)
                {
                    // print a Code 3 of 9 barcode with the data "123456789012" encoded
                    //   the 10 * 100, 60 * 100 parameters below specify the barcode's height and width
                    //   in the metric map mode (1cm tall, 6cm wide)
                    printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT, "123456789012", POSPrinterConst.PTR_BCS_Code39, 10 * 100, 60 * 100, POSPrinterConst.PTR_BC_CENTER, POSPrinterConst.PTR_BC_TEXT_BELOW);
                }
               
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|cA" + ESC + "|4C" + ESC + "|bC" + "Thank you" + LF);

                // the ESC + "|100fP" control code causes the printer to execute a paper cut
                //   after feeding to the cutter position
                printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|100fP");

                // terminate the transaction causing all of the above buffered data to be sent to the printer
                printer.transactionPrint(POSPrinterConst.PTR_S_RECEIPT, POSPrinterConst.PTR_TP_NORMAL);
               
                // exit our printing loop
            } while (false);
        }
        catch(JposException e)
        {
            // display any errors that come up
            e.printStackTrace();
        }
        finally
        {
            // close the printer object
            try
            {
                printer.close();
            }
            catch (Exception e) {}
        }
       
        System.out.println("StarReceiptTest finished.");
View Full Code Here

TOP

Related Classes of jpos.POSPrinter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.