public void TestPrintJob()
        {
            // TODO enter the name of your printer
            var printerName = "Reliance (Copy 1)";


            var printer = new ReliancePrinter(printerName);

            var lineOfText = string.Format("Today is {0}\n", DateTime.Now.ToLongDateString());

            // TODO There is an open task for bold, italics, etc.
            var receiptContent = new TextContent();

            receiptContent.SetTabStops(0, new [] { 100.0f, 50.0f, 50.0f, 50.0f });

            receiptContent.TextBuilder.Append("\n");
            receiptContent.TextBuilder.Append("Item\tPrice\tQuantity\tTotal\n");
            receiptContent.TextBuilder.Append("Lettuce\t$4.99\t3\t$14.97\n");
            receiptContent.TextBuilder.Append("Seedless Bun\t$1.99\t3\t$5.97\n");
            receiptContent.TextBuilder.Append("\n\n");
            receiptContent.TextBuilder.Append(new string('-', 78));
            receiptContent.TextBuilder.Append("\n\tTotal");
            receiptContent.TextBuilder.AppendFormat("\t\t$20.94\n\n");

            var welcomeFont = new Font("Tahoma", 22);
            var trailerFont = new Font("Courier Mono", 12);

            var content = new List <IContent>
            {
                new ImageContent(Resources.small_lettuce_burgers),
                new TextContent("Welcome", welcomeFont, StringAlignment.Center),

                receiptContent,

                new TextContent(lineOfText, trailerFont),
                new TextContent("Ticket #007", justification: StringAlignment.Far),
            };

            var document = new Document
            {
                DocumentContent = content,
                AutoSize        = true,
            };

            printer.PrintDocument(document);
        }
Example #2
0
        static void Main(string[] args)
        {
            const string phoenixPort  = "COM1";
            const string reliancePort = "COM12";

            const int captureRate = 10; // number of seconds between capture

            Console.WriteLine("Starting Security Camera Sample");


            // Setup the header with double width, double height, center justified
            var header = new StandardSection()
            {
                Justification = FontJustification.JustifyCenter,
                HeightScalar  = FontHeighScalar.h2,
                WidthScalar   = FontWidthScalar.w2,
                Font          = ThermalFonts.A,
                AutoNewline   = true,
            };



            // Setup timestamp at normal scalar with bold, underline, and centered
            var timestamp = new StandardSection()
            {
                Justification = FontJustification.JustifyCenter,
                HeightScalar  = FontHeighScalar.h1,
                WidthScalar   = FontWidthScalar.w1,
                Effects       = FontEffects.Italic | FontEffects.Underline,
                Font          = ThermalFonts.B,
                AutoNewline   = true,
            };

            // Print Status is shown as a JSON object
            var printStatus = new StandardSection()
            {
                Justification = FontJustification.JustifyLeft,
                HeightScalar  = FontHeighScalar.h1,
                WidthScalar   = FontWidthScalar.w1,
                Font          = ThermalFonts.C,
                AutoNewline   = true,
            };

            // Document template
            // Capture #{}
            // Image....
            // Image....
            // Image...
            // Timestamp
            var document = new StandardDocument()
            {
                // Don't forget to set your codepage!
                CodePage = CodePages.CPSPACE,
            };

            document.Sections.Add(header);
            document.Sections.Add(new Placeholder());  // Placeholder since we know we'll want an image here
            document.Sections.Add(timestamp);
            document.Sections.Add(printStatus);

            int count = 1;

            while (true)
            {
                // Select one printer or the other. Phoenix does not currently
                // support dynamic images over ESC/POS. Images will only
                // be transmitted through the print queue but no examples have
                // been prepared for this.
                //using (var printer = new PhoenixPrinter(phoenixPort))
                using (var printer = new ReliancePrinter(reliancePort))
                    using (var image = Webcam.GrabPicture())
                    {
                        var now = DateTime.Now;
                        Console.WriteLine("Image #{0} taken at {1}", count, now);


                        // Resize image if we want. This will follow ESC/POS justification
                        //logo.Resize(640, 480);
                        image.ApplyDithering(Algorithms.JarvisJudiceNinke, 128);

                        // Print the header document, update with new capture number
                        header.Content = string.Format("Capture #{0} (ЫВФАЫВМОЫВАП)", count);

                        // Printer the timestamp document
                        timestamp.Content = string.Format("{0}: {1}", count++, now);

                        // Get the latest printer status. Note that reliance and phoenix have
                        // slightly different args to this get status command
                        printStatus.Content = printer.GetStatus(StatusTypes.FullStatus).ToJSON(true);

                        // Re-assign this image to the middle part of the document
                        printer.SetImage(image, document, 1);

                        // Send the whole document + image
                        printer.PrintDocument(document);
                        printer.FormFeed();

                        // Wait for next capture period
                        Thread.Sleep(captureRate * 1000);
                    }
            }
        }