打印在C#中格式化的HTML页面 [英] Printing a formatted HTML page in C#
问题描述
我要寻找一种方式来打印在横向模式下格式化的html文件在C#中(主要是WPF)。打印对话框会以设置页面设置为横向是很好的。我试着使用微软的HTML为XAML转换器和它破坏了格式化。我觉得很神奇,没有任何方法或抓住一个文件,并直接发送到打印机。
I am looking for a way to print a formatted html file in landscape mode in c# (primarily wpf). Print dialog would be nice in order to set the page setting to landscape. I tried using Microsoft's html to xaml converter and it destroyed the formatting. I find it quite amazing that there is no method or grabbing a file and sending directly to a printer.
任何想法,将不胜感激。
Any ideas would be much appreciated.
推荐答案
您可以访问web浏览器类的print()方法,在C#中做到这一点。很酷的事情是,你并不需要实际应用程序中的任何位置显示web浏览器。只需简单地喂内容到WebBrowser控件,像这样:
You can access the Print() method of the WebBrowser Class, in C# to do this. The cool thing is that you don't need to actually display the WebBrowser anywhere in your application. Just simply feed the content to the WebBrowser Control like so:
webBrowser1.DocumentContent = openfiledialog.FileName;
和则只需调用 webBrowser1.Print();
方法。下面是一个MSDN参考:
And then just call the webBrowser1.Print();
method. Here's an MSDN reference:
的 http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.print.aspx
希望这有助于。
这篇关于打印在C#中格式化的HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!