
Я пытаюсь распечатать на принтере в классе C# с помощью Windows.Devices.PointOfService библиотека. Мой код:
Код: Выделить всё
public async Task PrintReceipt(string textToPrint)
{
try
{
PosPrinter posPrinter = await PosPrinter.GetDefaultAsync();
if (posPrinter == null)
{
// Handle case where no printer is found.
return;
}
_claimedPrinter = await posPrinter.ClaimPrinterAsync();
// Set the character set ID on the claimed printer object.
// 858 is a common European code page that includes '£'.
_claimedPrinter.CharacterSet = 858;
await _claimedPrinter.EnableAsync();
ReceiptPrintJob job = _claimedPrinter.Receipt.CreateJob();
//// Get the correct encoding for the WPC1252 code page
//Encoding wpc1252 = Encoding.GetEncoding(1252);
//// Convert the string to a byte array using the WPC1252 encoding
//byte[] encodedBytes = wpc1252.GetBytes(textToPrint);
//// Now, convert the byte array back to a string
//// This is the string you should send to the printer
//string encodedString = wpc1252.GetString(encodedBytes);
job.Print(textToPrint);
bool result = await job.ExecuteAsync();
if (result)
{
// Printing was successful.
}
else
{
logger.LogWarning("Printing failed. Checking printer status.");
if (_claimedPrinter.IsCoverOpen)
{
logger.LogWarning("Printer cover is open.");
}
if (_claimedPrinter.Receipt.IsPaperEmpty)
{
logger.LogWarning("Receipt printer is out of paper.");
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
finally
{
_claimedPrinter.Dispose();
}
}

Подробнее здесь: https://stackoverflow.com/questions/797 ... %a3-symbol