How to print a Word document from C#

随声附和 提交于 2019-12-20 06:11:24

问题


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.


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


来源:https://stackoverflow.com/questions/1021836/how-to-print-a-word-document-from-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!