Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过asp.net(c#)上的打印服务器打印文本_C#_Asp.net - Fatal编程技术网

通过asp.net(c#)上的打印服务器打印文本

通过asp.net(c#)上的打印服务器打印文本,c#,asp.net,C#,Asp.net,我需要打印一个文本内容,我使用这个代码,但不工作,纸张是空的 PrintDocument myPrintServer = new PrintDocument(); myPrintServer.PrinterSettings.PrinterName = @"\\servername\printerName"; StringReader myReader = new StringReader("test string content");

我需要打印一个文本内容,我使用这个代码,但不工作,纸张是空的

      PrintDocument myPrintServer = new PrintDocument();

        myPrintServer.PrinterSettings.PrinterName = @"\\servername\printerName";
        StringReader myReader = new StringReader("test string content");
        myReader.Close();
有人能告诉我怎么了吗


谢谢

您将myReader数据发送到打印服务器的位置?我在您的代码片段中看不到这一点


您可能希望签出该文件,特别是其中显示用于在打印画布上实际绘制的PrintPageEventHandler的部分。

您必须添加代码以将字符串呈现到您创建的PrintDocument对象的图形上下文中。请参阅并注意他们如何使用事件处理程序向页面呈现文本:

          pd.PrintPage += new PrintPageEventHandler
             (this.pd_PrintPage);
          pd.Print();
然后:

// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev) 
{

如果要从C#将预格式化数据直接发送到打印机,可以使用并执行以下操作 string s=“Hello”//依赖于设备的字符串,需要FormFeed吗

// Allow the user to select a printer.
PrintDialog pd  = new PrintDialog();
pd.PrinterSettings = new PrinterSettings();
if( DialogResult.OK == pd.ShowDialog(this) )
{
    // Send a printer-specific to the printer.
    RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, s);
}

谢谢你,但是还有另一种不用画图就把字符串发送到打印机的方法吗?让打印机(zebra zpl)解释这个字符串。我已经编辑了答案,包括向打印机发送一个原始字符串。这就是你要找的吗?
}
// Allow the user to select a printer.
PrintDialog pd  = new PrintDialog();
pd.PrinterSettings = new PrinterSettings();
if( DialogResult.OK == pd.ShowDialog(this) )
{
    // Send a printer-specific to the printer.
    RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, s);
}