2013-08-19 71 views
2

下面的代碼至少完美的作品打印在Windows 7中的PDF文件,但被吹在Windows 8中的錯誤:Windows 8打印錯誤的C#進程打印PDF文件,如何?

   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文件無論如何,但堅持我需要在Windows 8上工作,所以這個錯誤不會再發生。

編輯,現在這是在Windows 8怪異: printto不被識別爲一個內部或外部命令

我試着用搜索引擎這一點,但我驚呆了沒有結果上來。 我想要做的就是將我的文檔編程打印到特定的打印機。

回答

0

錯誤消息告訴你所有你需要知道的。在.pdf文件擴展名上沒有爲printto動詞定義的內容。如果你想要這種方法的話,你需要配置你的文件關聯來補救。

你試圖做到這一點的方式非常脆弱,依賴於它在第三方PDF閱讀器的模糊情況。如果您控制運行應用程序的所有計算機,則可以根據需要配置PDF查看器。否則,您可以期待處理大量的客戶支持。更強大的解決方案是使用提供此類功能的許多庫之一將PDF打印功能構建到您的應用程序中。

+0

當我點擊一個PDF文件並認爲它是Adobe時,它確實對我有誤導,因爲它確實是Windows 8的普通PDF查看器,它實際上沒有文件關聯。一旦我安裝了Adobe reader,並使用print命令假定使用它的默認打印機。那麼我可能需要爲舊的printto.exe文件保留那些不是默認打印機的副本。 – jfalberg

+0

沒有printto.exe文件。有一個動詞printto與.pdf擴展名關聯。 –

+0

我已經安裝了AdobeReader,並將其與pdf關聯,但這不起作用。它只是拋出:「指定的可執行文件不是該OS平臺的有效應用程序。」例外 –