简体   繁体   中英

How to print a Word document from C#

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.

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

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

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 printProcess = new System.Diagnostics.Process();
 printProcess.StartInfo.FileName = @"X:\test\print this.doc";
 printProcess.StartInfo.Verb = "Print";
 printProcess.StartInfo.CreateNoWindow = true;
 printProcess.Start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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