Print IHTMLDocument2 without dialog box

I worked on a project that automatically prints HTML invoices. This was especially difficult since I needed to format the CSS .

Following the tips, I found that IHTMLDocument2 used to do my printing. I should be able to:

 mshtml.IHTMLDocument2 doc = new mshtml.HTMLDocument() as mshtml.IHTMLDocument2; doc.write(htmlContent); //htmlContent is a string of HTML doc.execCommand("PRINT", false, null); 

The second argument indicates whether to create a Printer Options field, but this does not help. I read that using PRINT will always lead to a dialog box, however I could not find an alternative.

Any ideas?

+3
source share
1 answer

According to MSDN :

Print

Opens the print dialog so that the user can print the current page.

So, I think there is no way around this behavior. Try using other classes for your application or open the print dialog while printing. A.
It should be noted that you must specify true as the secord parameter ( showUI [in, optional] ) in the execCommand method.

+2
source

Source: https://habr.com/ru/post/1443043/


All Articles