private void PrintText(string printerLogicalName, Button printButton)
        {
            Jpos.POSPrinter p = new Jpos.POSPrinter(this);
            try
            {
                printButton.Enabled = false;

                p.Open(printerLogicalName); //SPP-R300
                p.Claim(0);
                p.DeviceEnabled = true;

                //Print out text. Be sure to have a new line (\n) at the end of the data.
                p.PrintNormal(
                    Jpos.POSPrinterConst.PtrSReceipt,
                    "This is a test.\nLorem Ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum.\nThis is a new line.\n");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                Toast.MakeText(this, "Error:\n" + e.StackTrace, ToastLength.Long).Show();
            }
            finally
            {
                printButton.Enabled = true;

                if (p != null)
                {
                    p.Close();
                }
            }
        }
        private void PrintPDF(string printerLogicalName, Button printButton)
        {
            Jpos.POSPrinter p        = new Jpos.POSPrinter(this);
            var             inStream = this.Resources.OpenRawResource(Resource.Raw.test_pdf);

            try
            {
                var personalDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                var pdfPath     = System.IO.Path.Combine(personalDir, "test.pdf");
                using (var file = File.Create(pdfPath))
                {
                    inStream.CopyTo(file);
                }

                printButton.Enabled = false;

                p.Open(printerLogicalName); //SPP-R300
                p.Claim(0);
                p.DeviceEnabled = true;

                for (int pageNumber = 0; pageNumber < PDF_PAGE_COUNT; pageNumber++)
                {
                    //Print PDF
                    p.PrintPDF(
                        Jpos.POSPrinterConst.PtrSReceipt,           //Print Type
                        pdfPath,                                    //Path to PDF file
                        1000,                                       //Width
                        Jpos.POSPrinterConst.PtrPdfLeft,            //Alignment
                        pageNumber,                                 //Page
                        50);                                        //Brightness
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                Toast.MakeText(this, "Error:\n" + e.StackTrace, ToastLength.Long).Show();
            }
            finally
            {
                printButton.Enabled = true;

                try
                {
                    if (inStream != null)
                    {
                        inStream.Close();
                    }

                    if (p != null)
                    {
                        p.Close();
                    }
                }
                catch (IOException e) { }
            }
        }
        private void PrintText(string printerLogicalName, Button printButton)
        {
            Jpos.POSPrinter p = new Jpos.POSPrinter(this);
            try
            {
                printButton.Enabled = false;

                p.Open(printerLogicalName); //SPP-R300
                p.Claim(0);
                p.DeviceEnabled = true;

                //Print out text. Be sure to have a new line (\n) at the end of the data.
                p.PrintNormal(
                    Jpos.POSPrinterConst.PtrSReceipt,
                    "This is a test.\nLorem Ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum lorum ipsum.\nThis is a new line.\n");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                Toast.MakeText(this, "Error:\n" + e.StackTrace, ToastLength.Long).Show();
            }
            finally
            {
                printButton.Enabled = true;

                if (p != null)
                    p.Close();
            }
        }
        private void PrintPDF(string printerLogicalName, Button printButton)
        {
            Jpos.POSPrinter p = new Jpos.POSPrinter(this);
            var inStream = this.Resources.OpenRawResource(Resource.Raw.test_pdf);
            try
            {
                var personalDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                var pdfPath = System.IO.Path.Combine(personalDir, "test.pdf");
                using (var file = File.Create(pdfPath))
                {
                    inStream.CopyTo(file);
                }

                printButton.Enabled = false;

                p.Open(printerLogicalName); //SPP-R300
                p.Claim(0);
                p.DeviceEnabled = true;

                for (int pageNumber = 0; pageNumber < PDF_PAGE_COUNT; pageNumber++)
                {
                    //Print PDF
                    p.PrintPDF(
                        Jpos.POSPrinterConst.PtrSReceipt,           //Print Type
                        pdfPath,                                    //Path to PDF file
                        1000,                                       //Width
                        Jpos.POSPrinterConst.PtrPdfLeft,            //Alignment
                        pageNumber,                                 //Page
                        50);                                        //Brightness
                }
            }
            catch(Exception e)
            {
                Console.WriteLine(e.StackTrace);
                Toast.MakeText(this, "Error:\n" + e.StackTrace, ToastLength.Long).Show();
            }
            finally
            {
                printButton.Enabled = true;
                
                try
                {
                    if (inStream != null)
                        inStream.Close();

                    if (p != null)
                        p.Close();
                }
                catch (IOException e) { }
            }
        }