简体   繁体   English

IHTMLDocument2不带对话框打印

[英]IHTMLDocument2 Printing without Dialog Box

I've been working on a project that automatically prints HTML invoices. 我一直在研究一个自动打印HTML发票的项目。 It's been particularly challenging as I've needed to keep the CSS formatting. 由于我需要保持CSS格式,因此特别具有挑战性。

Following advice, I've found myself using IHTMLDocument2 to carry out my printing. 根据建议,我发现自己使用IHTMLDocument2来执行打印。 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. 第二个参数指定是否生成“ Printer Options框,但它没有帮助。 I've read that using PRINT will always result in a dialog box - however I haven't been able to find an alternative. 我已经读过,使用PRINT总是会产生一个对话框 - 但是我还是找不到替代方案。

Any ideas? 有任何想法吗?

According MSDN : 根据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. 您应该注意,必须在execCommand方法中提供true作为secord参数( showUI [in, optional] )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM