从WPF web浏览器打印背景颜色 [英] Printing Background Colors from WPF WebBrowser

查看:268
本文介绍了从WPF web浏览器打印背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在打印WPF WebBrowser控件的内容,像这样:

Currently, I'm printing the contents of a WPF WebBrowser like so:

mshtml.IHTMLDocument2 doc = WebBrowser.Document as mshtml.IHTMLDocument2;
doc.execCommand("Print", true, null);

我的HTML内容与背景颜色表。目前,当我打印的内容,背景颜色不打印 - 一切都是白色固体。有没有办法告诉web浏览器打印背景颜色呢?

My HTML content has tables with background colors. Currently, when I print the content, the background colors do not print -- everything is solid white. Is there a way to tell the WebBrowser to print the background colors as well?

此外,这还是引起了打印对话框弹出。有谁知道命令是打印的内容是什么对话,少了?

Also, this still causes a print dialog to pop up. Does anyone know what the command is to print the contents dialog-less?

非常感谢!

推荐答案

假设你正在使用SHDocVw.WebBrowser',你可以使用 ExecWB 命令。要打印照片,无需对话框,使用 OLECMDEXECOPT_PROMPTUSER 1 )不变。您也可以通过一个IE打印模板(只是一个HTML文件)超过如何显示网页的更多控制。

Assuming you're using 'SHDocVw.WebBrowser', you can use the ExecWB command. To print without the dialog, use the OLECMDEXECOPT_PROMPTUSER (1) constant. You can also pass an IE print template (just an HTML file) for more control over how the page is displayed.

这件事情是这样的(从<一所href=\"http://social.msdn.microsoft.com/forums/en-US/winforms/thread/328ce789-d789-4d6b-8cff-ec920820e2a3/\"相对=nofollow>这个的MSDN问题)

It's something like this (taken from this MSDN question)

browser.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
               SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, 
               "print_template.html", ref nullObject);

至于大背景下,这似乎是你可以在打印模板的的 LayoutRect 。所有的打印对话框中设置都存储在注册表中 ,但打印模板是preferable因为它不会改变整个系统的设置。

As for the background, it appears to be one of the options you can specify in the print template's LayoutRect. All print dialog settings are stored in the registry, but a print template is preferable because it won't change system-wide settings.

这篇关于从WPF web浏览器打印背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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