6
votes

I am trying to make a Print application on UWP, but the samples show

await Windows.Graphics.Printing.PrintManager.ShowPrintUIAsync();

This brings the UWP Print Dialog.

I need to print directly without this dialog. How to do this?

I need something like

await Windows.Graphics.Printing.PrintManager.PrintAsync();

We should be able to programatically list printers, select the printer, configure paper size, orientation, settings...

3
It's been on UserVoice for FOUR YEARS now. This is insane...eltiare
This is a WinUI Proposal: Allow the App to Print without showing the Confirmation Dialog to user github.com/microsoft/microsoft-ui-xaml/issues/2126Tony

3 Answers

8
votes

The current UWP API does not support silent printing, i.e. without explicit user interaction.

For POS scenarios UWP does offer the POSPrinter API - this may or may not apply to your scenario though:

https://docs.microsoft.com/en-us/uwp/api/Windows.Devices.PointOfService.PosPrinter

https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/PosPrinter

For LOB applications running on desktop, you also have the option to continue using your Win32 printing APIs from a fulltrust process included in your UWP app package. I have put together a quick sample that demonstrates this technique in the example of printing image files silently from a UWP:

Store: https://www.microsoft.com/store/apps/9pd51nnkx3t2

Source: https://1drv.ms/u/s!AovTwKUMywTNnOsbzlRfghOikDy8Dw

It's certainly a valid feature request and we should extend the API to enable this scenario with the right user model in place (API, capability, settings, etc.) to ensure a proper user experience.

Please vote here on UserVoice to help the team prioritize the feature: https://wpdev.uservoice.com/forums/110705-universal-windows-platform/suggestions/6185763-allow-direct-printing-without-modern-ui-print-dial

3
votes

I am using RawPrint nuget to print silently in UWP:

https://github.com/frogmorecs/RawPrint

Sample:

  ...

  if (file != null)
  {
      IPrinter printer = new Printer();
      var stream = await file.OpenStreamForReadAsync();
      printer.PrintRawStream("Brother DCP-L2540DN series Printer", stream, file.DisplayName);
  }
2
votes

await Windows.Graphics.Printing.PrintManager.PrintAsync();

As far as I know, there is no such api for printer without PrintUI. And I search some similar issues. And the answer is negative. If you do want this feature, you are welcome to vote up on the UserVoice .