C# 获取所有安装了的打印机代码如下:
1
2
3
4
5
6
|
using System.Drawing.Printing; var printers = PrinterSettings.InstalledPrinters; foreach (var item in printers) { Console.WriteLine(item.ToString()); } |
C# 调用打印机打印文件,通常情况下,例如Word、Excel、PDF等可以使用一些对应的组件进行打印,另一个通用的方式是直接启用一个打印的进程进行打印。示例代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
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(); |
另外在生产环境中可能不支持PrintTo,判断一个文件在特定系统下有哪些可用的命令,需要在特定系统下执行下面的代码,下面的代码是判断某个文件在特定系统下所支持的命令:
1
2
3
4
5
6
7
8
9
|
using System.Diagnostics; string filePath = "文件路径" ; ProcessStartInfo info = new ProcessStartInfo(); info.FileName = filePath; foreach (var verb in info.Verbs) { Console.WriteLine(verb); } |
以上就是c#获取已安装的打印机并调用打印文件的详细内容,更多关于c# 打印文件的资料请关注服务器之家其它相关文章!
原文链接:https://www.cnblogs.com/godbell/p/11802478.html