IHTMLDocument2 Printing without Dialog Box

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-14 14:00:09

问题


I've been working on a project that automatically prints HTML invoices. It's been particularly challenging as I've needed to keep the CSS formatting.

Following advice, I've found myself using IHTMLDocument2 to carry out my printing. I'm supposed to 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 specifies whether to produce the Printer Options box, but it doesn't help. I've read that using PRINT will always result in a dialog box - however I haven't been able to find an alternative.

Any ideas?


回答1:


According MSDN:

Print

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

So I think there is no way to workaround this behaviour. Try to use other classes for your application or open the print dialog box during printing.
You should note that you must provide true as secord parameter (showUI [in, optional]) in execCommand method.



来源:https://stackoverflow.com/questions/13272704/ihtmldocument2-printing-without-dialog-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!