0

I'm trying to generate some html file and send it to the printer. In order to print the html page I used the CMD command print /D:PrinterName FilePath as process in my code.

When I start my program the printer prints the html code and not the web page as I expected. I understand why it happens but how can I print the html file as web page with the web page style and not as html code?

The reason I chose to generate the data as html file is because I can be very flexible in terms of style, I can control the elements style create tables and etc. So solutions like "generate the data as txt" won't be helpful.

Thank you very much.

AKX
  • 152,115
  • 15
  • 115
  • 172
DimDom
  • 27
  • 1
  • 6

2 Answers2

0

if you are saving the web page somewhere then you can give the path as input to the webBrowser.Print() method.

See the below link for more details:

https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.print.aspx

aditya
  • 343
  • 2
  • 14
0

I find this solution from here

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();
}
Emdadul Sawon
  • 5,730
  • 3
  • 45
  • 48