Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing a formatted HTML page in C#

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.

like image 735
Demetri Avatar asked Oct 14 '10 14:10

Demetri


1 Answers

 WebBrowser myWebBrowser = new WebBrowser();
        private void Form1_Load(object sender, EventArgs e)
        {
            myWebBrowser.DocumentCompleted += myWebBrowser_DocumentCompleted;
            myWebBrowser.DocumentText  =System .IO.File .ReadAllText ( @"C:\a.htm");
        }

        private void myWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            myWebBrowser.Print();
        }
like image 119
Thunder Avatar answered Oct 25 '22 21:10

Thunder