wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
25.16k stars 1.21k forks source link

Feature: Allow silent printing #3259

Open cstenglein opened 8 months ago

cstenglein commented 8 months ago

Is your feature request related to a problem? Please describe.

No response

Describe the solution you'd like

First of all, thank you very much for this project. :)

As a devleoper, I would like to have the option to print a page "silently", meaning without showing the print dialog. This is usually used in kiosk environments, e.g. for printing photos.

Electron already does this with the webContents.print function.

Wails only has the WindowPrint function which calls window.print (see frontend.go.

Describe alternatives you've considered

No response

Additional context

No response

leaanthony commented 8 months ago

Great suggestion 👍 Do you know how electron implemented it? My guess is "outside the browser"...

cstenglein commented 8 months ago

Since you are using WebView2 for the windows part, you could print silently there:

https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/print?tabs=win32cpp#the-print-method-to-customize-printing

See the Print statement:

Silently prints the current top-level document in the WebView2 using optional programmatically specified print settings to a printer. You can use this to build your own Print Preview dialog or print experience.

Do you know how electron implemented it? My guess is "outside the browser"...

The closest I can find is the Print method in electron_api_web_contents.cc, which collects the options and forwards the job to a print_task_runner_.