用于打印pdf文件的c#进程Windows 8出错,怎么样?

以下代码至少可以在Windows 7中完美地打印pdf文件,但在Windows 8中出现错误:

Process process = new Process(); //process.StartInfo.CreateNoWindow = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.FileName = defFile; if (rwPrinter.Length > 0) { process.StartInfo.Verb = "printto"; process.StartInfo.Arguments = "\"" + rwPrinter + "\""; } else { process.StartInfo.Verb = "print"; } process.Start(); 

以下是错误的一些细节:

 ************** Exception Text ************** System.ComponentModel.Win32Exception (0x80004005): No application is associated with the specified file for this operation at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at ECitation.Form1.process_ticket(String jobdo) at ECitation.Form1.btnPrint_Click(Object sender, EventArgs e) 

我知道有一个adobe阅读器的pdf文件,但我仍然坚持我需要在Windows 8上工作,所以这个错误不会再发生。

编辑,现在这在Windows 8中很奇怪:printto不被识别为内部或外部命令

我试着谷歌搜索这个但是很震惊没有结果出现。 我想要做的就是以编程方式将文档打印到特定的打印机。

错误消息告诉您需要知道的所有信息。 .pdf文件扩展名上的printto动词没有定义。 如果您希望这种方法起作用,则需要配置文件关联以解决该问题。

您尝试这样做的方式非常脆弱,依赖于第三方PDF查看器的迷宫。 如果您控制运行应用程序的所有计算机,则可以根据需要配置PDF查看器。 否则,您可以期望处理大量客户支持。 更强大的解决方案是使用提供此类function的众多库之一,在您的应用程序中构建PDF打印function。