c#interop.word - 打印输出 - 随机更改打印机设置

时间:2013-02-28 08:53:09

标签: c# printing ms-word interop office-interop

我对Interop有一个非常奇怪的问题。

我开发了一个小程序,打开 Microsoft.Office.Interop.Word.Application 并用它来打印文档:

object[] oWordDialogParams = { printerName, true };
string[] argNames = { "Printer", "DoNotSetAsSysDefault" };
object wordBasic = wordApplication.WordBasic;
try
{
  wordBasic.GetType().InvokeMember("FilePrintSetup"
  , BindingFlags.InvokeMethod
  , null
  , wordBasic
  , oWordDialogParams
  , null
  , null
  , argNames);
}
catch (Exception e)
{
  Logger.Instance.Log("failed to set printer");
}
doc.Activate(); 
wordApplication.PrintOut(Background: ref backgroundPrint, FileName: ref sourceFile);

一切都很好(我会说95%的时间),我能够看到正确的打印队列,最重要的是,打印机设置默认打印机设置(即:打印机首选项中没有任何反应):

ok http://img687.imageshack.us/img687/8866/72957735.png

但是,在少数情况下,文档将传递给打印机而没有扩展名(在本例中为docx)并且打印机设置已更改(例如,纸张大小设置为字母)

notok http://img547.imageshack.us/img547/1699/image001w.png

请注意:

  • 在我的代码中, FileName:ref sourceFile 始终使用扩展名正确设置,但(随机!)它出现在没有扩展名的打印队列中。 发生这种情况时,也意味着打印机设置更改为非默认值

  • 完全相同的文件转载工作正常(!)

我正在使用:

  • framework 4.0
  • interop 12.0
  • Windows Server 2008 R2
  • 打印机使用HP通用打印驱动程序

谢谢大家的宝贵帮助!

0 个答案:

没有答案
相关问题