【问题标题】:Windows 8 blows error on c# process for printing pdf file, how?Windows 8 在打印 pdf 文件的 c# 进程中出现错误,如何处理?
【发布时间】:2013-08-19 18:36:20
【问题描述】:

以下代码至少可以在 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)

我知道无论如何都有一个用于 pdf 文件的 adobe 阅读器,但我不知道在 Windows 8 上工作需要什么,所以这个错误不会再次发生。

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

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

【问题讨论】:

    标签: c# pdf printing process


    【解决方案1】:

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

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

    【讨论】:

    • 当我点击一个 pdf 文件并认为它是 Adob​​e 时,它​​确实是 Windows 8 的通用 PDF 查看器,实际上没有文件关联,这对我来说确实是一种误导。一旦我安装了 Adob​​e 阅读器并使用打印命令假设使用它工作的默认打印机。我可能需要为那些没有默认使用该打印机的人保留旧的 printto.exe 文件的副本。
    • 没有 printto .exe 文件。有一个动词 printto,与 .pdf 扩展名相关联。
    • 我已经安装了 Adob​​eReader 并将其与 pdf 关联,但这不起作用。它只是抛出:“指定的可执行文件不是此操作系统平台的有效应用程序。”异常
    猜你喜欢
    • 1970-01-01
    • 2013-07-11
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    • 1970-01-01
    • 2018-04-05
    • 2011-03-14
    • 1970-01-01
    相关资源
    最近更新 更多