c# - 如何在选定的打印机中打印任何文档

标签 c# .net printing shellexecute

我想使用 .net 在选定的打印机中打印任何文档,例如 pdf、word、excel 或文本文件。我已经成功在默认打印机中进行此类打印。现在唯一的问题是在选择的打印机。

这是打印代码。

public bool Print(string FilePath)
    {
        if (File.Exists(FilePath)) {
            if (ShellExecute((System.IntPtr )1, "Print", FilePath, "", Directory.GetDirectoryRoot(FilePath), SW_SHOWNORMAL).ToInt32() <= 32) {
                return false;
            } else {
                return true;
            }
        } else {
            return false;
        }
    }

最佳答案

Process printJob = new Process();
printJob.StartInfo.FileName = path;
printJob.StartInfo.UseShellExecute = true;
printJob.StartInfo.Verb = "printto";
printJob.StartInfo.CreateNoWindow = true;
printJob.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
printJob.StartInfo.Arguments = "\"" + printerAddress + "\"" + " " + printerExtraParameters;
printJob.StartInfo.WorkingDirectory = Path.GetDirectoryName(path);
printJob.Start();

关于c# - 如何在选定的打印机中打印任何文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3138181/

相关文章:

c# - 从 C# 桌面应用程序到受 Siteminder 保护的服务器的 HTTP 请求

.net - Excel xml 电子表格 - 是否可以嵌入图像?

java - jpos.JposException : It could not complete output within the specified period

c# - XNA 游戏中的分辨率

c# - 为什么我的 http 请求响应不能解析成一个整数?

c# - 当您通过 .NET Remoting 从远程对象返回 Stream 时到底发生了什么

python - 按字母顺序排列的字典键

javascript - 有没有人能够使用 CSS3 在 Chrome 中以横向模式成功打印?

c# - 如何将此 HipChat curl 帖子转换为 C#?

.net - 什么时候不实现通用接口(interface)?