2

The following code at least works perfectly printing a pdf file in Windows 7, but is blowing an error in 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();

Here are some details of the error:

************** 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)

I know there's an adobe reader for pdf files anyways but am stuck as to what I need to get working on Windows 8 so this error doesn't happen again.

edit, now this is weird in Windows 8: printto is not recognized as an internal or external command

I tried googling this but am shocked no results come up. All I want to do is programmically print my document to a specific printer.

4

1 回答 1

0

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

您尝试执行此操作的方式非常脆弱,因为它依赖于第三方 PDF 查看器的模糊性。如果您控制运行应用程序的所有机器,您可以根据需要配置 PDF 查看器。否则,您可能需要处理大量的客户支持。更强大的解决方案是使用提供此类功能的众多库之一将 PDF 打印功能构建到您的应用程序中。

于 2013-08-19T20:11:25.320 回答