On click of a button, I am trying to print the HTML page
I think the problem is in the path? Without hardcoding how should I print this document, currently it just opens the printer tray and prints This page cant be displayed
.
help.html
<html>
<head>
<body>
This is my testing...
<body>
</head>
</html>
Here is my C# code
private void button1_Click(object sender, EventArgs e)
{
// Create a WebBrowser instance.
WebBrowser webBrowserForPrinting = new WebBrowser();
// Add an event handler that prints the document after it loads.
webBrowserForPrinting.DocumentCompleted +=
new WebBrowserDocumentCompletedEventHandler(PrintDocument);
// Set the Url property to load the document.
webBrowserForPrinting.Url = new Uri(@"D:\PMO Project\PMO\WindowsFormsApplication1\WindowsFormsApplication1\HTML\help.html");
}
private void PrintDocument(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
// Print the document now that it is fully loaded.
((WebBrowser)sender).Print();
// Dispose the WebBrowser now that the task is complete.
((WebBrowser)sender).Dispose();
}
Screenshot of what is printed