没有对话框的IHTMLDocument2打印 [英] IHTMLDocument2 Printing without Dialog Box

查看:110
本文介绍了没有对话框的IHTMLDocument2打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究自动打印HTML发票的项目.因为我需要保持CSS格式,所以这特别具有挑战性.

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.

根据建议,我发现自己使用IHTMLDocument2进行打印.我应该能够:

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);

第二个参数指定是否产生Printer Options框,但这无济于事.我已经读到,使用PRINT总是会出现一个对话框-但是我找不到替代方法.

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.

有什么想法吗?

推荐答案

根据

打印

打开打印对话框,以便用户可以打印当前页面.

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

因此,我认为没有办法解决此问题.尝试对您的应用程序使用其他类,或在打印过程中打开打印"对话框.
您应该注意,必须在execCommand方法中提供true作为第二个参数(showUI [in, optional]).

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.

这篇关于没有对话框的IHTMLDocument2打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆