C# 调用打印机打印文件,通常情况下,例如Word、Excel、PDF等可以使用一些对应的组件进行打印,另一个通用的方式是直接启用一个打印的进程进行打印。示例代码如下:
using System.Diagnostics; string filePath = "文件路径"; string printer = "打印机"; ProcessStartInfo info = new ProcessStartInfo(); info.Arguments = "\"" + printer + "\""; info.Verb = "PrintTo"; info.FileName = filePath; info.CreateNoWindow = true; info.WindowStyle = ProcessWindowStyle.Hidden; Process p = new Process(); p.StartInfo = info; p.Start(); p.WaitForInputIdle();