tryphotino / photino.NET

https://tryphotino.io
Apache License 2.0
885 stars 73 forks source link

Native printing on Windows #178

Closed nicholas-brooks closed 5 months ago

nicholas-brooks commented 5 months ago

Hello! Awesome library I've stumbled across. Wish it was more well known.

I'm looking to allow a user to perform native printing from a Web-Client. Scenario: A customer needs to print out delivery dockets and performs this task 100's of times a day. Currently the web-application generates a PDF of the delivery docket, which the customer then opens in a separate browser tab, hits Ctrl+P to open the browser print dialog, then selects the Print button in browser print dialog. Not efficient for the user.

Ideally we want to speed this up for the customer so we're thinking of wrapping our SPA web-client in a Native windows application using Photino.NET. Then when the user wants to print the delivery docket:

  1. The user selects the print button in the SPA web-client.
  2. The web-client then sends a command to the native-app using window.external.sendMessage(`{ "command": "print", "url": "http://../doc.pdf" }\`)
  3. The native-app receives the command using a delegate, then
  4. Downloads the PDF at the provided url, saves it to a temporary location.
  5. The native-app prompts the user for the Printer using the WinForms PrintDialog dialog.
  6. Then, uses a third-party library to send the PDF to the selected printer.

I've put together a test project to at https://github.com/nicholas-brooks/photino-dummy-print to demonstrate the part of prompting the user for the printer using PrintDialog

Do you see any issues in doing so? I understand this ties the native-app to Windows, but for our scenario that is fine for now.

Note: I am not a WinForms expert at all so I'm probably missing lots of obvious issues here. I've done extensive Win32 coding via Delphi in the past, but most of my recent work is backend dotnet services and spa web-clients.

nicholas-brooks commented 5 months ago

An update on this:

We replaced the use of the PrintDialog with the following:

We did this so we can now remember the selected printer for the particular document type the user prints as well as make it a more consistent ux experience for the user.