views:

59

answers:

3

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.

+1  A: 

It sounds to me like the best way you'd want to go is to first pick the HTML rendering engine and look to it for print support. There is no "standard" way to print an HTML document regardless of language, OS, or framework.

James Dunne
+2  A: 

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;

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

Hope this helps.

lucifer
A: 

Maybe something like:

webBrowser1.DocumentContent = YOUR_FILE_NAME;
mshtml.IHTMLDocument2 doc = webBrowser1.Document as mshtml.IHTMLDocument2;
doc.execCommand("Print", true, null);
Kamyar