Download
https://www.neodynamic.com/products/printing/js-print-manager/blazor/download/
Install
To download & installĀ JSPrintManager for Blazor, run the following command in theĀ Package Manager Console
PM> Install-Package Neodynamic.Blazor.JSPrintManager
Blazor Project Setup
Project.cs
using Neodynamic.Blazor;
builder.Services.AddJSPrintManager(); // JSPrintManager service
_Import.razor
@using Neodynamic.Blazor
ReceiptPrinter.razor
@page "/Setting/ReceiptPrinter"
@inherits ReceiptPrinterBase
<div style="text-align:center">
<h1>Receipt Printer Test</h1>
</div>
ReceiptPrinter.cs
        [Inject]
        public JSPrintManager JSPrintManager { get; set; }
        protected override void OnAfterRender(bool firstRender)
        {
            if (firstRender)
            {
                // Handle OnStatusChanged event to detect any WSS status change
                JSPrintManager.OnStatusChanged += () =>
                {
                    // Status = Open means that JSPM Client App is up and running!
                    if (JSPrintManager.Status == JSPMWSStatus.Open)
                    {
                        // Create a ClientPrintJob
                        var cpj = new ClientPrintJob();
                        // Set Default Printer
                        cpj.ClientPrinter = new DefaultPrinter();
                        string cmds;
                        // Start of Receipt
                        cmds = RawPosCommand.INITIALIZE;
                        // Receipt Header
                        cmds += RawPosCommand.ALIGN_CENTER;
                        cmds += RawPosCommand.FONT_H2;
                        cmds += "This is the header";
                        cmds += RawPosCommand.NEWLINE;
                        cmds += RawPosCommand.FONT_NORMAL;
                        cmds += "123 Test Street";
                        cmds += RawPosCommand.NEWLINE;
                        cmds += "San Diego, " + "CA" + " " + "92121";
                        cmds += RawPosCommand.NEWLINE;
                        cmds += "858-123-4567";
                        cmds += RawPosCommand.NEWLINE2;
                        cmds += RawPosCommand.ALIGN_LEFT;
                        cmds += "Employee: John Doe";
                        cmds += RawPosCommand.NEWLINE;
                        cmds += RawPosCommand.ALIGN_LEFT;
                        cmds += "Order Date: " + Convert.ToDateTime(DateTime.Now).ToString("MM/dd/yyyy hh:mm tt");
                        cmds += RawPosCommand.NEWLINE;
                        cmds += "Order Type: In Store Purchase";
                        cmds += RawPosCommand.NEWLINE;
                        cmds += "Order Number: 123456789";
                        cmds += RawPosCommand.NEWLINE2;
                        cmds += RawPosCommand.ALIGN_CENTER;
                        cmds += "Order Status: ORDER PAID";
                        cmds += RawPosCommand.NEWLINE;
                        cmds += RawPosCommand.FONT_H2;
                        cmds += RawPosCommand.NEWLINE2;
                        // Receipt Body
                        cmds += RawPosCommand.ALIGN_LEFT;
                        cmds += RawPosCommand.FONT_H2;
                        cmds += "Item".PadRight(23) + "Qty".PadLeft(5) + "Price".PadLeft(10) + "Amount".PadLeft(10);
                        cmds += RawPosCommand.NEWLINE;
                        cmds += RawPosCommand.FONT_NORMAL;
                        cmds += "------------------------------------------------";
                        cmds += RawPosCommand.NEWLINE;
                        cmds += RawPosCommand.NEWLINE2;
                        // Receipt Footer
                        cmds += RawPosCommand.FONT_NORMAL;
                        cmds += RawPosCommand.ALIGN_CENTER;
                        cmds += "This is the footer";
                        cmds += RawPosCommand.NEWLINE2;
                        cmds += RawPosCommand.NEWLINE2;
                        cmds += RawPosCommand.NEWLINE2;
                        cmds += RawPosCommand.CUT;
                        // Set the RAW commands to send to the printer...
                        cpj.PrinterCommands = cmds;
                        // PRINT IT!!!
                        JSPrintManager.SendClientPrintJob(cpj);
                    }
                };
                // Start WebSocket comm
                JSPrintManager.Start();
            }
            base.OnAfterRender(firstRender);
        }
											
Comments