C# 用C语言打印HTML页面#
点击一个按钮,我试图打印HTML页面 我想问题出在路上了?如果没有硬编码,如何打印此文档,当前它只打开打印机托盘并打印C# 用C语言打印HTML页面#,c#,C#,点击一个按钮,我试图打印HTML页面 我想问题出在路上了?如果没有硬编码,如何打印此文档,当前它只打开打印机托盘并打印,无法显示此页面 help.html <html> <head> <body> This is my testing... <body> </head> </html> 打印内容的屏幕截图 您能给我们看一下“打印机托盘”的屏幕截图吗?或者你的意思是物理打印机上的物理试纸弹出了?@EdPlunkett我刚刚
,无法显示此页面
help.html
<html>
<head>
<body>
This is my testing...
<body>
</head>
</html>
打印内容的屏幕截图
您能给我们看一下“打印机托盘”的屏幕截图吗?或者你的意思是物理打印机上的物理试纸弹出了?@EdPlunkett我刚刚检查了打印机打印的页面,但不是它正在打印的html页面(doenst print help.html),但它打印的页面无法显示res://ieframe.dll/dnserrordiaoff.htmIs 你的help.html有效吗?您是否尝试在浏览器中打开它?@MegaTron question使用htmlI更新,如项目目录的硬编码路径。这是一个小细节,比如说,在没有走到打印机前看看是否有纸出来的情况下,就发布了一个关于为什么不打印的问题,这确实给我们带来了一个问题。但别介意我,我是一个残忍而古怪的老人。我建议您暂时将WebBrowser控件放在您可以看到它的UI中,并找出如何将HTML文件编译为资源并加载到WebBrowser中。一旦你能在屏幕上看到它,就开始打印它。那你就可以完成这项工作了。
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();
}