简体   繁体   English

C# 打印 Word 文档而不打开 Word 或 Printerselection

[英]C# Print Word Document without opening Word or Printerselection

I tried using the code below, using PrintDocument , etc.. but can't get it to work.我尝试使用下面的代码,使用PrintDocument等。但无法让它工作。

Every time I run the Code below it opens a window asking me to select a printer.每次我运行下面的代码时,它都会打开一个 window 询问我 select 打印机。 Using PrintDocument always led to empty pages, but the docs got printed.使用PrintDocument总是会导致页面空白,但文档会被打印出来。

How can I print Word documents without opening any windows?如何在不打开任何 windows 的情况下打印 Word 文档?

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);

}

Only the Word application can correctly print a Word document as it interprets the content/layout as it's sent to the printer.只有 Word 应用程序可以正确打印 Word 文档,因为它会在将内容/布局发送到打印机时对其进行解释。 You first need to open the document in the Word application, then use its PrintOut method.您首先需要在 Word 应用程序中打开文档,然后使用其PrintOut方法。

(This is also what Windows does when a user right-clicks a Word file and selects "Print".) (这也是 Windows 在用户右键单击 Word 文件并选择“打印”时所做的事情。)

So there's no way to print a document without opening a window.因此,如果不打开 window,就无法打印文档。 You can, however, minimize the Word document window once it's been opened.但是,您可以在打开 Word 文档 window 后将其最小化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM