如何从C#打印Word文档

时间:2022-10-30 21:32:01

How can I launch the print of a document from C# .NET application ? the Word document already exists in the hard drive. I just wish to start printing that Word document upon the button click event.

如何从C#.NET应用程序启动文档打印? Word文档已存在于硬盘驱动器中。我只想在按钮点击事件上开始打印Word文档。

2 个解决方案

#1


 ProcessStartInfo psi = new ProcessStartInfo(wordFilename)
 {
    UseShellExecute = true,
    Verb = "print",
    RedirectStandardOutput = false,
    CreateNoWindow = true
 };

 using (Process p = new Process {StartInfo = psi})
 {
     p.Start();
     p.WaitForExit();
 }

#2


To do this kind of thing you need to know about System.Diagnostics.Process , the MSDN page shows how to pridnt a Word document as an example. A short version:

要执行此类有关System.Diagnostics.Process的操作,MSDN页面将显示如何将Word文档作为示例进行pridnt。简短版本:

 System.Diagnostics.Process printProcess = new System.Diagnostics.Process();
 printProcess.StartInfo.FileName = @"X:\test\print this.doc";
 printProcess.StartInfo.Verb = "Print";
 printProcess.StartInfo.CreateNoWindow = true;
 printProcess.Start();

#1


 ProcessStartInfo psi = new ProcessStartInfo(wordFilename)
 {
    UseShellExecute = true,
    Verb = "print",
    RedirectStandardOutput = false,
    CreateNoWindow = true
 };

 using (Process p = new Process {StartInfo = psi})
 {
     p.Start();
     p.WaitForExit();
 }

#2


To do this kind of thing you need to know about System.Diagnostics.Process , the MSDN page shows how to pridnt a Word document as an example. A short version:

要执行此类有关System.Diagnostics.Process的操作,MSDN页面将显示如何将Word文档作为示例进行pridnt。简短版本:

 System.Diagnostics.Process printProcess = new System.Diagnostics.Process();
 printProcess.StartInfo.FileName = @"X:\test\print this.doc";
 printProcess.StartInfo.Verb = "Print";
 printProcess.StartInfo.CreateNoWindow = true;
 printProcess.Start();