nwenar abbas

nwenar abbas

  • 1.6k
  • 108
  • 3.4k

Uwp Pos Printer Gets

Apr 3 2024 11:49 PM

uwp cant find the defualt or any printer that has been connected to my computer meanwhile other apps or i can do printing in via the printdocment class but I need a silent pring for this porpuse i have 

PosPrinter printer = await PosPrinter.FromIdAsync(id);
ClaimedPosPrinter claimed = await printer.ClaimPrinterAsync();
ReceiptPrintJob job = claimed.Receipt.CreateJob();
job.PrintLine("Hello World");

and I get the id here 

string id = "";
string deviceSelector = "System.Devices.InterfaceClassGuid:=\"{0ecef634-6ef0-472a-8085-5ad023ecbccd}\"";
var devices = await DeviceInformation.FindAllAsync(deviceSelector);
ListOfPrinters.Items.Clear();

// Display information about each printer
foreach (var device in devices)
{
    if (device.Name == "4BARCODE 4B-2083A")
    {
        Debug.WriteLine($"Printer Name: {device.Name}");
        Debug.WriteLine($"Id: {device.Id}");
        Debug.WriteLine($"Kind: {device.Kind}");
        Debug.WriteLine($"IsDefault: {device.IsDefault}");
        Debug.WriteLine("---");
        ListOfPrinters.Items.Add(device.Name);
        id = device.Id;
    }
}

the second bunch finds the printer i target even I can put the printer name in a combo box i have shared the printer id to the FromIdAsync method but the  ClaimedPosPrinter throws an exception which says 

System.NullReferenceException: 'Object reference not set to an instance of an object.'

printer was null.

Note// I have tried to put the id as hardcoded many ways 

Note// I have tried GetDefaultAsync but had no chance 


Answers (1)