.NET: How to print files w/o opening them

前端 未结 6 803
长情又很酷
长情又很酷 2021-01-05 07:53

We have an application that basically archives files and we give the user the possibility to print these files. They can be .txt, .doc, .pdf, .jpg nothing fancy. Is there a

6条回答
  •  抹茶落季
    2021-01-05 08:38

    My understanding is that most apps will open (even briefly) when you print. Try right-clicking a MS Word document and hitting print. You'll see Word open, print, and close.

    However, you might want to add this to your code to keep the process hidden and to close when finished:

    p.Start();
    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    if (p.HasExited == false)
    {
       p.WaitForExit(10000);
    }
    
    p.EnableRaisingEvents = true;
    p.CloseMainWindow();
    p.Close();
    

提交回复
热议问题