我在使用C#中的webbrowser控件时遇到了一些麻烦,尤其是当我打印它时。问题是,我的html文件中有条形码,我必须打印它(我使用字体来创建代码)。当我用Firefox或任何其他Web浏览器打开html文件时,我的裸码很好,我可以扫描它。但是,当我在c#中使用我的webbrowser打开我的文件时,或者当我打印它时,webbrowser在裸码之后添加2个字符。而且,当我打印文件时,我的文档没有居中,就像webbrowser添加了一个margin-left属性。所以我的问题是,有没有办法打印一个html文件,使用webbroser,当我使用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页”和标题。