横向打印 HTML 文件目录的最佳方法是什么?我不介意显示打印对话框。我尝试了几种解决方案(用尽 Google 和 StackOverflow),它们要么将 HTML 打印为字符串,要么无法横向打印。
我正在使用 .NET 2.0 Win Forms 项目来创建 HTML 报告。现在我需要将它们发送到打印机假脱机。
谢谢
更新 :
正确理解需求后即可实现
//The example is using WebBrowser Control Version 4.0.0.0 .NET Component
//MSDN : http://msdn.microsoft.com/en-us/library/2te2y1x6(v=vs.80).aspx
//Example 1 : You can print html string using the Web Browser Control
string htmlString = "<html><head><title>Printing from Win forms - Web Browser Control</title></head><body><h1>Hello World....</h1></body></html>";
webBrowser1.DocumentText = htmlString;
//Example 2 : Print file or URL using the Web Browser Control
webBrowser1.Url = new Uri("http://www.stackoverflow.com/faq");
//Call Print function or Print Dialog
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(PrintFile);
private void PrintFile(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//You can setup page e.g. Orientation to Landscape and choose one of the Print options below
(WebBrowser)sender).ShowPageSetupDialog();
// Print the document now that it is fully loaded.
((WebBrowser)sender).Print();
//OR
(WebBrowser)sender).ShowPrintDialog();
//OR Even better setup print options and then Print
(WebBrowser)sender).ShowPrintPreviewDialog();
// Dispose the WebBrowser now that the task is complete.
((WebBrowser)sender).Dispose();
}