如何从Web服务器确认成功打印的打印格式的文本? [英] How to print formatted text from a web server with confirmation of successful printing?

查看:135
本文介绍了如何从Web服务器确认成功打印的打印格式的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个将下载格式的文本从Web服务器的系统,打印格式的文本,确认打印作业成功完成,然后响应Web服务器,让它知道文字印刷。所有无用户输入

I am trying to build a system that will download formatted text from a web server, print the formatted text, confirm that the print job completed successfully and then respond to the web server to let it know the text was printed. All without user input.

我已经使用的 Web浏览器控制下载HTML,然后打印出来,而不需要用户输入。然而,这属于短,对确认打印的能力。

I have had success using the Web Browser control to download HTML and then print it without needing user input. This falls short, however, on the ability to confirm the printing.

它看起来像 System.Printing 您可以访问打印服务器和打印队列和使用,既可以启动打印作业,还可以找到的打印作业的状态。

It looks like in System.Printing you can access a PrintServer and a PrintQueue and use that both to start print jobs and also find the status of print jobs.

我还没有能够证实的打印作业,但我已经能够发起简单的打印。然而,这并不携带任何在HTML从Web服务器格式化的。我不依赖于HTML,但是它必须是可以由网络服务器来制造,因此它可以无需更新客户端应用程序来改变一些格式。

I haven't yet been able to confirm a print job, but I have been able to initiate simple printing. However, this does not carry any of the HTML formatting from the web server. I'm not tied to HTML, but it has to be some formatting that can be produced by the web server so it can be altered without needing to update the client application.

我如何打印从Web服务器,正确的格式输出,并且知道打印作业是否成功还是失败?

How can I print the output from the web server, properly formatted, and know whether the print job succeeds or fails?

推荐答案

我假设你愿意使用WebBrowser控件。这里是一个解决方案确认打印。基本上你需要处理的 PrintTemplateTeardown 事件等待打印作业完成。

I'm assuming that you are willing to use the WebBrowser control. Here is a solution to confirm the printing. Basically you need to handle the PrintTemplateTeardown event to wait for the print job to complete.

下面是一个简单的code从答案中提取:<一href="http://stackoverflow.com/questions/419412/print-html-document-from-windows-service-without-print-dialog">Print从Windows服务没有打印对话框 html文件

The following is a sample code extracted from answer in: Print html document from Windows Service without print dialog

using System.Reflection;
using System.Threading;
using SHDocVw;

namespace HTMLPrinting
{
  public class HTMLPrinter
  {
    private bool documentLoaded;
    private bool documentPrinted;

    private void ie_DocumentComplete(object pDisp, ref object URL)
    {
      documentLoaded = true;
    }

    private void ie_PrintTemplateTeardown(object pDisp)
    {
      documentPrinted = true;
    }

    public void Print(string htmlFilename)
    {
      documentLoaded = false;
      documentPrinted = false;

      InternetExplorer ie = new InternetExplorerClass();
      ie.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(ie_DocumentComplete);
      ie.PrintTemplateTeardown += new DWebBrowserEvents2_PrintTemplateTeardownEventHandler(ie_PrintTemplateTeardown);

      object missing = Missing.Value;

      ie.Navigate(htmlFilename, ref missing, ref missing, ref missing, ref missing);
      while (!documentLoaded && ie.QueryStatusWB(OLECMDID.OLECMDID_PRINT) != OLECMDF.OLECMDF_ENABLED)
        Thread.Sleep(100);

      ie.ExecWB(OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref missing, ref missing);
      while (!documentPrinted)
        Thread.Sleep(100);

      ie.DocumentComplete -= ie_DocumentComplete;
      ie.PrintTemplateTeardown -= ie_PrintTemplateTeardown;
      ie.Quit();
    }
  }
}

您也可以参考: http://jiangsheng.net/SynchronousWebBrowserPrinting.aspx

希望它能帮助!

这篇关于如何从Web服务器确认成功打印的打印格式的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆