我有C#程序,它在生成过程中将使用PrintTo谓词发送以将文件打印到指定的打印机。但是,当我尝试打印.pdf或html文件时,它说
Unhandled Exception: System.ComponentModel.Win32Exception: No application is associated with the specified file for this operation
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
我已经安装了PDF Complete,并且双击pdf文件可以正确打开它。 .html文件也会发生相同的事情(我将Mozilla Firefox作为默认浏览器)。
我的代码:
ProcessStartInfo info = new ProcessStartInfo(args[0]);
info.Arguments = "\"" + args[1] + "\"";
info.CreateNoWindow = true;
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
info.UseShellExecute = true;
info.Verb = "PrintTo";
Process.Start(info);
和命令行调用:>myapp.exe D:\Temp\test.pdf "PDF Complete"
例如>myapp.exe D:\Temp\test.txt "PDF Complete"
有效
对于仍然有兴趣的人。 PDF Complete和Firefox都不完全支持PrintTo动词
我在打印.pdf的方法上有类似的错误。一切正常,直到我的计算机由于硬盘控制器上的阵列故障而崩溃。
重建计算机后,我回到完成此代码部分的位置。但是,它不起作用-我在上面的OP中列出了错误。
[经过一番检查并检查了该线程后,我发现Windows 10使用Edge处理.pdf文件。我安装了Adobe Reader和中提琴〜!不再有错误,Process.Start()打印文件。