kitchen receipt + html printer

This commit is contained in:
EugeneTes
2026-01-14 11:47:43 +01:00
parent 011978136d
commit 147265358f
16 changed files with 1346 additions and 178 deletions

View File

@@ -1,12 +1,14 @@
using Inspectron.Epson;
using Inspectron.Epson.PrintServer.Printers.Utils;
using Inspectron.Epson.PrintServer.Printers.Utils.FinalRecipe;
using Inspectron.Epson.PrintServer.Printers.Utils.KitchenReceipt;
using Inspectron.Epson.SOAP;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System.Text;
using System.Text.Json;
using System.Xml.Linq;
using FinalReceipt = Inspectron.Epson.PrintServer.Printers.Utils.FinalRecipe.FinalReceipt;
//SoapEpsonPrinter printer = new SoapEpsonPrinter("localhost:8888");
@@ -56,125 +58,202 @@ using System.Xml.Linq;
//Console.ReadLine();
//var receipt = new Receipt
var receipt = new FinalReceipt
{
CompanyName = "Klingler Gastro AG",
Address1 = "Münzplatz 3",
Address2 = "CH-8001 Zürich",
Phone = "043 321 22 22",
ReceiptNumber = "1-81-202",
DateTime = new DateTime(2025, 12, 16, 14, 58, 0),
Guests = 2,
Total = 160.00m,
Currency = "CHF",
TotalInAlternateCurrency = 172.80m,
AlternateCurrency = "EUR",
PaymentMethod = "MASTER",
PaymentAmount = 160.00m,
WaiterName = "Yves",
Terminal = "Hauptkasse ZH",
TableNumber = "12",
VatNumber = "CHE-449.635.880 MWST",
ThankYouMessage = "Das Team bedankt sich herzlich für Ihren",
GoodbyeMessageLine1 = "Besuch.",
GoodbyeMessageLine2 = "Auf Wiedersehen."
};
// Add items
receipt.Items.Add(new ReceiptItem
{
Quantity = 1,
Description = "San Pellegrino 50cl",
UnitPrice = 6.50m,
TotalPrice = 6.50m,
TaxCategory = "A"
});
receipt.Items.Add(new ReceiptItem
{
Quantity = 1,
Description = "Panna 50cl",
UnitPrice = 6.50m,
TotalPrice = 6.50m,
TaxCategory = "A"
});
receipt.Items.Add(new ReceiptItem
{
Quantity = 1,
Description = "Granini Tomatensaft",
UnitPrice = 5.50m,
TotalPrice = 5.50m,
TaxCategory = "A"
});
receipt.Items.Add(new ReceiptItem
{
Quantity = 2,
Description = "Business Lunch Menu Seco",
UnitPrice = 44.00m,
TotalPrice = 88.00m,
TaxCategory = "A"
});
receipt.Items.Add(new ReceiptItem
{
Quantity = 2,
Description = "Brunello di Montalcino 1",
UnitPrice = 16.00m,
TotalPrice = 32.00m,
TaxCategory = "A"
});
receipt.Items.Add(new ReceiptItem
{
Quantity = 2,
Description = "Espresso",
UnitPrice = 5.50m,
TotalPrice = 11.00m,
TaxCategory = "A"
});
receipt.Items.Add(new ReceiptItem
{
Quantity = 1,
Description = "Tip",
UnitPrice = 10.50m,
TotalPrice = 10.50m,
TaxCategory = "B"
});
// Add tax breakdown
receipt.TaxBreakdown.Add(new TaxInfo
{
Category = "A",
Rate = 8.1m,
Gross = 149.50m,
Net = 138.30m,
TaxAmount = 11.20m,
Currency = "CHF"
});
receipt.TaxBreakdown.Add(new TaxInfo
{
Category = "B",
Rate = 0m,
Gross = 10.50m,
Net = 10.50m,
TaxAmount = 0.00m,
Currency = "CHF"
});
// Convert to print commands
var converter = new ReceiptConverter(lineWidth: 48, bigFontLineWidth: 24);
var printCommands = converter.ConvertToPrintCommands(receipt);
// Print the commands
Console.WriteLine("=== PRINT COMMANDS ===\n");
var printer = new HtmlPrinter(@".\test.html", paperWidth: 384);
await printer.ConnectAsync("");
await printer.SetAbsolutePrintPosition(97);
await printer.LoadImageAsync("ristorante-klinglers.ch-logo_white_bg.png", 390);
await printer.SetAbsolutePrintPosition(0);
await printer.PrintLoadedImage();
await Task.Delay(200);
await printer.FeedLinesAsync(1);
await printer.SetCustomLineSpacing(22);
foreach (var command in printCommands)
{
string attributes = "";
if (command.IsBig) attributes += "[BIG] ";
if (command.IsBold) attributes += "[BOLD] ";
Console.WriteLine($"{attributes}{command.Text}");
if (command.IsBig)
{
await printer.SetFontSizeAsync(2, 1);
}
else
{
await printer.SetFontSizeAsync(1, 1);
}
//await Task.Delay(200);
await printer.SetEmphasized(command.IsBold);
//await Task.Delay(200);
await printer.PrintTextAsync(command.Text + "\n");
//await Task.Delay(200);
}
//var receipt = new KitchenReceipt
//{
// CompanyName = "Klingler Gastro AG",
// Address1 = "Münzplatz 3",
// Address2 = "CH-8001 Zürich",
// Phone = "043 321 22 22",
// ReceiptNumber = "1-81-202",
// DateTime = new DateTime(2025, 12, 16, 14, 58, 0),
// Guests = 2,
// Total = 160.00m,
// Currency = "CHF",
// TotalInAlternateCurrency = 172.80m,
// AlternateCurrency = "EUR",
// PaymentMethod = "MASTER",
// PaymentAmount = 160.00m,
// ServerName = "Yves",
// Terminal = "Hauptkasse ZH",
// TableNumber = "12",
// VatNumber = "CHE-449.635.880 MWST",
// ThankYouMessage = "Das Team bedankt sich herzlich für Ihren",
// GoodbyeMessageLine1 = "Besuch.",
// GoodbyeMessageLine2 = "Auf Wiedersehen."
// Title = "Warme Küche",
// TransactionDateTime = new DateTime(2025, 10, 23, 12, 18, 0),
// ReceiptNumber = "132018166",
// WaiterName = "Mariano Amato",
// WaiterId = "32 (VK Restaurant)",
// TableNumber = 22
//};
//// Add items
//receipt.Items.Add(new ReceiptItem
//{
// Quantity = 1,
// Description = "San Pellegrino 50cl",
// UnitPrice = 6.50m,
// TotalPrice = 6.50m,
// TaxCategory = "A"
//});
//// Add dishes (this section can be empty if no dishes were ordered)
//receipt.Items.Add(new ReceiptItem
//{
// Quantity = 1,
// Description = "Panna 50cl",
// UnitPrice = 6.50m,
// TotalPrice = 6.50m,
// TaxCategory = "A"
//});
//receipt.Gangs.Add(new Gang(1, "Gang"));
//receipt.Gangs.Add(new Gang(2, "Gang"));
//receipt.Items.Add(new ReceiptItem
//{
// Quantity = 1,
// Description = "Granini Tomatensaft",
// UnitPrice = 5.50m,
// TotalPrice = 5.50m,
// TaxCategory = "A"
//});
//receipt.Items.Add(new ReceiptItem
//{
// Quantity = 2,
// Description = "Business Lunch Menu Seco",
// UnitPrice = 44.00m,
// TotalPrice = 88.00m,
// TaxCategory = "A"
//});
//receipt.Items.Add(new ReceiptItem
//{
// Quantity = 2,
// Description = "Brunello di Montalcino 1",
// UnitPrice = 16.00m,
// TotalPrice = 32.00m,
// TaxCategory = "A"
//});
//receipt.Items.Add(new ReceiptItem
//{
// Quantity = 2,
// Description = "Espresso",
// UnitPrice = 5.50m,
// TotalPrice = 11.00m,
// TaxCategory = "A"
//});
//receipt.Items.Add(new ReceiptItem
//{
// Quantity = 1,
// Description = "Tip",
// UnitPrice = 10.50m,
// TotalPrice = 10.50m,
// TaxCategory = "B"
//});
//// Add tax breakdown
//receipt.TaxBreakdown.Add(new TaxInfo
//{
// Category = "A",
// Rate = 8.1m,
// Gross = 149.50m,
// Net = 138.30m,
// TaxAmount = 11.20m,
// Currency = "CHF"
//});
//receipt.TaxBreakdown.Add(new TaxInfo
//{
// Category = "B",
// Rate = 0m,
// Gross = 10.50m,
// Net = 10.50m,
// TaxAmount = 0.00m,
// Currency = "CHF"
//});
//receipt.Gangs[0].Dishes.Add(new Dish(1, "Avocado Sashimi"));
//receipt.Gangs[0].Dishes.Add(new Dish(1, "Baby Spinach Salad with Truffl"));
//receipt.Gangs[0].Dishes.Add(new Dish(1, "Beef Tataki"));
//receipt.Gangs[0].Dishes.Add(new Dish(1, "Salmon Taco"));
//// Convert to print commands
//var converter = new ReceiptConverter(lineWidth: 48, bigFontLineWidth: 24);
//receipt.Gangs[1].Dishes.Add(new Dish(1, "Avocado Sashimi"));
//receipt.Gangs[1].Dishes.Add(new Dish(1, "Baby Spinach Salad with Truffl"));
//receipt.Gangs[1].Dishes.Add(new Dish(1, "Beef Tataki"));
//receipt.Gangs[1].Dishes.Add(new Dish(1, "Salmon Taco"));
//receipt.Dishes.Add(new Dish(1, "Avocado Sashimi"));
//receipt.Dishes.Add(new Dish(1, "Baby Spinach Salad with Truffl"));
//receipt.Dishes.Add(new Dish(1, "Beef Tataki"));
//receipt.Dishes.Add(new Dish(1, "Salmon Taco"));
//// Add additional info
//receipt.AdditionalInfo.Add("1 x Amuse Bouche");
//KitchenReceiptConverter converter = new KitchenReceiptConverter(bigLineWidth: 20, lineWidth:33);
//var printCommands = converter.ConvertToPrintCommands(receipt);
//// Print the commands
//Console.WriteLine("=== PRINT COMMANDS ===\n");
//await printer.SetAbsolutePrintPosition(97);
//await printer.LoadImageAsync("ristorante-klinglers.ch-logo_white_bg.png",390);
//await printer.SetAbsolutePrintPosition(0);
//var printer = new HtmlPrinter(@".\test.html", paperWidth: 258);
//await printer.ConnectAsync("");
//await Task.Delay(200);
//await printer.FeedLinesAsync(1);
//await printer.SetCustomLineSpacing(22);
@@ -183,6 +262,7 @@ using System.Xml.Linq;
// string attributes = "";
// if (command.IsBig) attributes += "[BIG] ";
// if (command.IsBold) attributes += "[BOLD] ";
// if (command.IsRed) attributes += "[RED] ";
// Console.WriteLine($"{attributes}{command.Text}");
@@ -194,6 +274,9 @@ using System.Xml.Linq;
// {
// await printer.SetFontSizeAsync(1, 1);
// }
// await printer.SetRedColor(command.IsRed);
// //await Task.Delay(200);
// await printer.SetEmphasized(command.IsBold);
@@ -230,24 +313,24 @@ using System.Xml.Linq;
//await Task.Delay(200);
//KitchenReceiptPrinter krp = new KitchenReceiptPrinter(33);
var receipt = new KitchenReceipt(
Location: "Warme Küche",
Date: "23-Okt-25 12:18 Nr.:13201B166",
Owner: "Mariano Amato\n32 (VK Restaurant)",
Tisch: "22",
items: new List<KitchenItem>
{
new KitchenGang("1. Gang"),
new KitchenProduct(1, "Avocado Sashimi"),
new KitchenProduct(1, "Baby Spinach Salad with Truffl"),
new KitchenGang("2. Gang"),
new KitchenProduct(1, "Beef Tataki"),
new KitchenProduct(1, "Salmon Taco")
}
);
//var receipt = new TranslatedKitchenReceipt(
// Location: "Warme Küche",
// Date: "23-Okt-25 12:18 Nr.:13201B166",
// Owner: "Mariano Amato\n32 (VK Restaurant)",
// Tisch: "22",
// items: new List<KitchenItem>
// {
// new KitchenGang("1. Gang"),
// new KitchenProduct(1, "Avocado Sashimi"),
// new KitchenProduct(1, "Baby Spinach Salad with Truffl"),
// new KitchenGang("2. Gang"),
// new KitchenProduct(1, "Beef Tataki"),
// new KitchenProduct(1, "Salmon Taco")
// }
//);
var test = JsonSerializer.Serialize(receipt, new JsonSerializerOptions() { WriteIndented = true });
Console.WriteLine(test);
//var test = JsonSerializer.Serialize(receipt, new JsonSerializerOptions() { WriteIndented = true });
//Console.WriteLine(test);
////// Create printer with 42 character line width (default)
//var commands = krp.ConvertToCommands(receipt);