6

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...

Tony
  • 16,527
  • 15
  • 80
  • 134
  • This is on UserVoice https://wpdev.uservoice.com/forums/110705-universal-windows-platform/suggestions/6185763-allow-direct-printing-without-modern-ui-print-dial – Tony Feb 08 '18 at 19:10
  • 3
    It's been on UserVoice for FOUR YEARS now. This is insane... – eltiare Apr 06 '18 at 23:47
  • This is a WinUI Proposal: Allow the App to Print without showing the Confirmation Dialog to user https://github.com/microsoft/microsoft-ui-xaml/issues/2126 – Tony Mar 18 '20 at 00:45

3 Answers3

8

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://learn.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

Stefan Wick MSFT
  • 13,600
  • 1
  • 32
  • 51
  • Also, in WPF I used to specify Print Sizes of the Page and printed objects (Border) in cm, for example. – Tony Oct 30 '17 at 15:37
  • Best app description ever. "Sample to demonstrate interop with Win32 printing API" – Jerry Nixon Nov 02 '17 at 21:47
  • I think it is a good feature, please create the API, capability, settings, etc. needed to programatically select the Printer then Silent Print on UWP. See https://wpdev.uservoice.com/forums/110705-universal-windows-platform/suggestions/6185763-allow-direct-printing-without-modern-ui-print-dial – Tony Dec 14 '17 at 12:51
  • 1
    Is UserVoice still the best place to go for this? I'm banging my head against the wall trying to figure out how to get a Zebra printer to work with UWP. – eltiare Apr 06 '18 at 23:50
  • 1
    @eltiare The feature is still in the backlog. More votes will help the print team prioritize. The only workaround for now is to use a desktop extension process like I am doing in my simple image printing demo above. – Stefan Wick MSFT Apr 07 '18 at 14:29
3

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);
  }
Nikomac
  • 41
  • 3
2

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 .

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36