Print HTML Document from Windows Service in C# Without Print Dialog

How to print WebBrowser control content without showing print dialog?

In the recent versions of the WebBroswer control, Print() prints to the default printer without showing any dialog:

webBrowser1.Print();

It's equivalent to getting an instance of IWebBrowser2 from the WebBrowser.ActiveXInstance property and then call its ExecWB method by passing OLECMDID_PRINT as command and OLECMDEXECOPT_DONTPROMPTUSER to specify not showing the prompt:

int OLECMDID_PRINT = 6;
int OLECMDEXECOPT_DONTPROMPTUSER = 2;
dynamic iwb2 = webBrowser1.ActiveXInstance;
iwb2.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, null, null);

Or in a single line of code:

((dynamic)webBrowser1.ActiveXInstance).ExecWB(6, 2, null, null);

Printing a page without the Print dialog box?

I think you have confused client side printing with printing on the server.

You can print on the client side with Java, how some coupon printers work. However, this is frowned upon. The client should always have a choice of how they want it printed.

The calls on Page_Load would be done on the server-side printers.



Related Topics



Leave a reply



Submit