private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            System.Threading.Thread.Sleep(10000);
            try
            {
                screen_image = GetScreenCapture();   //Get bitmap image of the screen
                String myMacAddress = textBox1.Text; //Printer's Bluetooth MAC Address.
                ZebraPrinterConnection zebraPrinterConnection = new BluetoothPrinterConnection(myMacAddress);
                zebraPrinterConnection.Open();
                ZebraPrinter printer = ZebraPrinterFactory.GetInstance(zebraPrinterConnection);

                int x = 10;
                int y = 200;
                zebraPrinterConnection.Write(Encoding.Default.GetBytes("! 0 200 200 1200 1\r\n"));
                printer.GetGraphicsUtil().PrintImage(screen_image, x, y, -1, -1, true);  //Print the screen caputre image.
                zebraPrinterConnection.Write(Encoding.Default.GetBytes("FORM\r\nPRINT\r\n"));
                zebraPrinterConnection.Close();
            }
            catch
            {
                MessageBox.Show("Unable to print screen image");
            }

            this.Show();
        }
        /**
         * When a ZebraPrinterConnection has been established, this method
         * gets the printer and gathers information from the printer such as
         * the printer language and prints to the printer
         * **/

        private void threadedConnect(String addressName)
        {
            try
            {
                /**
                 * Open the connection
                 * **/
                connection.Open();
                Thread.Sleep(1000);
            }
            catch (ZebraPrinterConnectionException)
            {
                updateGuiFromWorkerThread("Unable to connect with printer", Color.Red);
                disconnect();
            }
            catch (Exception)
            {
                updateGuiFromWorkerThread("Error communicating with printer", Color.Red);
                disconnect();
            }

            printer = null;
            if (connection != null && connection.IsConnected())
            {
                /**
                 * Get the printer instance and the printer language, then print image
                 * **/
                try
                {
                    updateGuiFromWorkerThread("Getting printer...", Color.Goldenrod);
                    Thread.Sleep(1000);
                    printer = ZebraPrinterFactory.GetInstance(connection);
                    updateGuiFromWorkerThread("Got Printer, getting Language...", Color.LemonChiffon);
                    Thread.Sleep(1000);
                    PrinterLanguage pl = printer.GetPrinterControlLanguage();
                    updateGuiFromWorkerThread("Printer Language " + pl.ToString(), Color.LemonChiffon);
                    Thread.Sleep(1000);
                    updateGuiFromWorkerThread("Formatting Image", Color.AliceBlue);
                    printer.GetGraphicsUtil().PrintImage(image, 0, 0, 550, 412, false);
                    updateGuiFromWorkerThread("Printing To " + addressName, Color.Green);
                    Thread.Sleep(2000);
                    disconnect();
                }
                catch (ZebraPrinterConnectionException)
                {
                    updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                    printer = null;
                    Thread.Sleep(1000);
                    disconnect();
                }
                catch (ZebraPrinterLanguageUnknownException)
                {
                    updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                    printer = null;
                    Thread.Sleep(1000);
                    disconnect();
                }
            }
            updateButtonFromWorkerThread(true);
        }
Exemplo n.º 3
0
        /**********************************************************************************
         * Desc: This sends the selected image file to zebra printer for printing.
         ***********************************************************************************/
        private void printImage(String filePath)
        {
            if (zebraPrinterConnection != null && macAddrBox.Text.Length == 12)
            {
                ZebraPrinter printer = ZebraPrinterFactory.GetInstance(zebraPrinterConnection);

                // Send image to print
                printer.GetGraphicsUtil().PrintImage(filePath, 0, 0, 550, 412, false);
            }
        }
Exemplo n.º 4
0
            public void printFile(string fileURI, IReadOnlyDictionary <string, string> options, IMethodResult oResult)
            {
                Logger.Write("printFile call");
                Logger.Write("fileURI: " + fileURI);
                Logger.Write("options:", options);

                if (m_connection != null && m_printer != null)
                {
                    try
                    {
                        if (Path.GetExtension(fileURI) == ".jpg" || Path.GetExtension(fileURI) == ".png")
                        {
                            m_printer.GetGraphicsUtil().PrintImage(fileURI, 0, 0);
                            oResult.set(ZebraConstants.PRINTER_STATUS_SUCCESS);
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }

                oResult.set(ZebraConstants.PRINTER_STATUS_ERR_NOT_CONNECTED);
            }