从C#到网络打印机打印doc,docx,pdf,rtf和txt文件

时间:2018-06-12 08:51:04

标签: c# printing

我需要将设置格式(doc,docx,pdf,rtf和txt)的文件打印到软件网络打印机,但是我找不到轻松打印这些文档的方法。

我已经尝试了File.Copy(),但这失败了 - 打印机无法处理这项工作。我尝试将这种方法用于实际的打印机并将文本弄乱,因此显然无法正常工作。

我也尝试过Word Interop,但是我甚至在试图让它工作时遇到了很多麻烦,DCOM异常被抛到了一边。我不会再进一步​​尝试这条道路了。

var word = new Microsoft.Office.Interop.Word.Application { Visible = false };
var doc = word.Documents.Open(file.FullName, Visible: false);
doc.Application.ActivePrinter = @"\\server01\printer01";
doc.PrintOut(Pages: "1");
doc.Close();
break;
  

^第一行失败,出现以下错误:

     

"Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))."

我没有使用Process.Start动词尝试Print,因为您似乎无法指定特定的打印机。

如何轻松打印这些文件,最好不需要购买第三方软件?

0 个答案:

没有答案
相关问题