1

我在 C# 中使用 webbrowser 控件时遇到了一些问题,尤其是在我打印它时。问题是,我的 html 文件中有一个条形码,我必须打印它(我使用字体来创建代码)。当我用 Firefox 或任何其他 Web 浏览器打开 html 文件时,我的裸代码很好,我可以扫描它。但是,当我在 c# 中使用我的网络浏览器打开我的文件时,或者当我打印它时,网络浏览器会在裸代码后添加 2 个字符。而且,当我打印文件时,我的文档没有居中,就像网络浏览器添加了一个 margin-left 属性。所以我的问题是,有什么方法可以使用网络浏览器打印 html 文件,例如,当我使用 firefox 或 chrome 时,我如何查看 html 文件。这是我使用的代码。

curDir = Directory.GetCurrentDirectory();
webBrowserA4.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(PrintDocument);
webBrowserA4.Url = new Uri(String.Format("file:///{0}/print.html", curDir));

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();
}

编辑:所以,现在,我有另一个问题,这是我打印文件时的屏幕:http: //imgur.com/q7ovEA1如您所见,有一个“margin-left”,并且我无法删除它。我还想删除此“第 1 页,共 1 页”和标题。

4

0 回答 0