【问题标题】:C#, already able to print using hidden process, how to print to specific printerC#,已经能够使用隐藏进程打印,如何打印到特定打印机
【发布时间】:2017-05-01 20:03:44
【问题描述】:

我有以下 C# 代码可以成功打印提供的文件。这是在 Windows 7 中。

    // Uses the Default settings of the Windows Environment to open the file and send to printer
    // Seen: http://stackoverflow.com/a/6106155
    public void printPdfHiddenProcess(string filename)
    {
        ProcessStartInfo info = new ProcessStartInfo();
        Process p;

        // Set process setting to be hidden
        info.Verb = "print";
        info.FileName = filename;
        info.CreateNoWindow = true;
        info.WindowStyle = ProcessWindowStyle.Hidden;

        // Start hidden process
        p = new Process();
        p.StartInfo = info;
        p.Start();

        // Give the process some time
        p.WaitForInputIdle();
        Thread.Sleep(1000);

        // Close it
        if (p.CloseMainWindow() == false)
        {
            p.Close();
        }
    }

但是,这会导致它打印到默认打印机。 ProcessStartInfo 似乎没有提供可用于传递打印机名称的特定方法,但我可能遗漏了一些东西。

如何使用隐藏进程打印到特定打印机?

【问题讨论】:

    标签: c# windows printing process


    【解决方案1】:

    Print 使用默认值,要使用另一个你可以使用 PrintTo 并命名它。类似于 Save vs Save As

    info.Verb = "PrintTo";               // was "Print"
    string PrinterName = "Some Printer"; // add printer specific name here...
    info.Arguments = PrinterName;
    

    更多信息:Print documents... using the printto verb

    【讨论】:

    • 看起来很有希望,但它对我还不起作用。将阅读该链接,看看我是否能弄清楚。
    • 我成功了!我不得不更改 info.Arguments,我直接传递了打印机名称,就像在 info.Arguments = printerName; 中一样,它起作用了。如果您可以更新您的答案以至少注意这一点,我很乐意接受。
    • 用您的 cmets 更新答案
    猜你喜欢
    • 1970-01-01
    • 2020-06-10
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-10
    • 1970-01-01
    相关资源
    最近更新 更多