【问题标题】:How to Print raw data in WPF如何在 WPF 中打印原始数据
【发布时间】:2023-03-21 15:44:01
【问题描述】:

我正在研究如何在 WPF 中将原始数据发送到打印机。这类似于 Microsoft 解决方案 http://support.microsoft.com/kb/322091/en-us 但我希望它使用 Windows 控件在 wpf Vice 中。使用 wpf 的标准打印不起作用,因为我需要发送原始数据而不是文档页。我已经知道如何打印项目,但不使用自定义对话框或使用 winforms 就无法获取打印机名称。有谁知道怎么做?

我正在打印到热敏打印机,这就是为什么我不能在 wpf 中使用 printdocument 或类似项目。

【问题讨论】:

    标签: wpf printing


    【解决方案1】:

    终于想通了。示例代码如下:

    using System.Printing;
    
    PrintDialog _printDialog = new PrintDialog();
    bool? _print = _printDialog.ShowDialog();
    
    if (_print == true)
    {
        string _printerName = **_printDialog.PrintQueue.FullName**;
        RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, s)
    }
    

    RawPrinterHelper 来自上面的 Microsoft 文章。要获取选定的打印机,您需要使用 PrintQueue.FullName 属性。请注意,全名可能不会在 Intellisense 中显示,但确实有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多