I have a WPF
application that uses the WebBrowser
control in order to print html
documents.
My problem is that from time to time some of the characters are missing from the generated documents.
I tried to replace the printer and cables and I also validated the html
markup here.
This is how I generate the printing:
public static class HtmlPrint
{
public static void Print(string html, string documentTitle)
{
var wb = new System.Windows.Forms.WebBrowser { DocumentText = html };
wb.DocumentCompleted += wb_DocumentCompleted;
}
private static void wb_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
var wb = ((System.Windows.Forms.WebBrowser)sender);
wb.Print();
wb.Dispose();
}
}
HTML sample:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Items report</title>
<style type='text/css'>
html, body {
margin: 0;
padding: 0;
border: 0;
width: 100%;
}
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size: 11px;
color: #333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
margin-top: 10px;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
/*white-space:nowrap*/
}
</style>
</head>
<body dir="rtl">
<h3>15/12/2015 09:22:17</h3>
<h3>Items for station: 1</h3>
<br />
<table class="gridtable">
<tr>
<th>Location</th>
<th>Item</th>
<th>Description</th>
<th>Color</th>
<th>Size</th>
<th>Qty</th>
<th>Remarks</th>
</tr>
<tr>
<td>AD393</td>
<td>06957TO_GRE_S</td>
<td>Green shirt</td>
<td>GREEN-GRAY</td>
<td>S(36)</td>
<td>0</td>
<td>AD-37-5<br />AD-38-3<br />AD-38-5<br />AD-39-0<br />AD-39-3<br />AD-39-5<br />BC-38-1</td>
</tr>
<tr>
<td>CA183</td>
<td>A100000000464</td>
<td>White golf shirt</td>
<td>WHITE</td>
<td>XS/S (34-36)</td>
<td>0</td>
<td>AI-25-1<br />AK-25-1<br />AK-36-6<br />AK-37-6<br />AL-24-1<br />AL-25-1<br />CA-18-3</td>
</tr>
</table>
Any ideas on how to fix it?
UPDATE
I've tried using the System.Windows.Controls.WebBrowser
as follows but it prints empty pages:
public static void Print(string html)
{
/*
html is the actual HTML data e.g.
<!DOCTYPE html>
<html lang="he-IL" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9">
...
*/
try
{
var wb = new System.Windows.Controls.WebBrowser();
wb.LoadCompleted += Wb_LoadCompleted; //never called
wb.Loaded += Wb_Loaded; //never called
wb.NavigateToString(html);
mshtml.IHTMLDocument2 doc = wb.Document as mshtml.IHTMLDocument2;
doc.execCommand("Print", true, false);
}
catch (Exception ex)
{
//no exception raised
throw;
}
}