C# 在不打开 Word 或 Printerselection 的情况下打印 Word 文档

C# Print Word Document without opening Word or Printerselection

我尝试使用下面的代码,使用 PrintDocument 等,但无法正常工作。

每次我 运行 下面的代码都会打开 window 要求我 select 打印机。使用 PrintDocument 总是导致空白页,但文档已打印出来。

如何在不打开任何文档的情况下打印 Word 文档windows?

foreach (string doc in dirFiles) 
{
    ProcessStartInfo info = new ProcessStartInfo();

    info.Verb = "print";
    info.FileName = doc;
    info.Arguments = SelectedDrucker; //Printername
    info.CreateNoWindow = true;

    Process.Start(info);

}

只有 Word 应用程序可以正确打印 Word 文档,因为它会在发送到打印机时解释 content/layout。您首先需要在 Word 应用程序中打开文档,然后使用其 PrintOut 方法。

(这也是当用户右键单击 Word 文件并选择 "Print" 时 Windows 所做的。)

所以不打开 window 就无法打印文档。但是,您可以在打开 Word 文档后将其最小化 window。