2

我想在.net core 中打印。为此,我正在使用Process. System.Diagnostics我尝试了以下代码:

var printJob = new Process
{
    StartInfo = new ProcessStartInfo
    {
        FileName = path,
        UseShellExecute = true,
        Verb = "print",
        CreateNoWindow = true,
        WindowStyle = ProcessWindowStyle.Hidden,
        WorkingDirectory = Path.GetDirectoryName(path)
    }

};

但是.net 核心Verb中缺少属性。StartInfo所以我决定按如下方式打印:

Process.Start("LPR -S ip -P 'Star TSP800L Peeler (TSP828L)' -o 'D:\testpdf.pdf'");

但它给了我

该系统找不到指定的文件

而文件存在于给定位置。

现在我正在尝试在我的 Windows 10 机器上使用本地打印机进行测试,但我需要的是从 ubuntu 机器打印到网络打印机。

有人可以告诉我,为什么我收到文件未找到错误。我找到了以下链接,但它使用的是 StartInfo,在这种情况下对我没有帮助。

Process.Start in C# The system cannot find the file specified error

Process.Start() 中的错误——系统找不到指定的文件

4

1 回答 1

0

做这样的事情:

 public static void PrintToASpecificPirnter()
        {
            using (PrintDialog printDialog = new PrintDialog())
            {
                printDialog.AllowSomePages = true;
                printDialog.AllowSelection = true;
                if (printDialog.ShowDialog() == DialogResult.OK)
                {
                    var StartInfo = new ProcessStartInfo
                    {
                        CreateNoWindow = true,
                        UseShellExecute = true,
                        Verb = "printTo",
                        Arguments = "\"" + printDialog.PrinterSettings.PrinterName + "\"",
                        WindowStyle = ProcessWindowStyle.Hidden,
                        FileName = fileName
                    };

                    Process.Start(StartInfo);
                }

            }
    }
于 2021-12-27T22:03:33.817 回答