1

I have a docx document, which I want to print from code behind in C#. I had gone through forums and few say, its not possible, i will have to use JavaScript. How to specify file in JavaScript, print code? So far I have done in code behind direct print.

Process process = new Process();
process.StartInfo.FileName = file;
process.StartInfo.Verb = "print";
process.Start();
//process.Kill();
Incredible
  • 3,495
  • 8
  • 49
  • 77
  • Semi-unrelated to your question, but you shouldn't kill your process immediately after starting it - then surely nothing will happen. Just start the process, and let it do its job. Only kill the process if you absolutely need to. – Lars Kristensen Aug 22 '13 at 09:51
  • 1
    ok, but I am also looking for the printer dialog to appear, how to do that? – Incredible Aug 22 '13 at 09:54

2 Answers2

1

There have been a few of these posted here. This one would best suite I think.

Printing using Word Interop with Print Dialog

The basic premise is that you need to open the file in code using Microsoft.Office.Interop libraries, then perform your print. You can't just point the print process at a file.

Edit: PrintDialog class should help you with dialog.

Community
  • 1
  • 1
Papa
  • 1,628
  • 1
  • 11
  • 16
  • i am trying to print a document using javascript, the problem is i dont want to show print dialog, but manually pass number of copies and specify pages. can someone help me out? it would be great if i could get my hands on some javascript snippet. – Atif Imtiaz Nov 06 '13 at 05:43
  • Not sure if that's possible. Javascript's window.print doesn't allow any parameters and the browser will be the one handling the print process. It's up the user's browser preferences. – Papa Nov 06 '13 at 11:07
-1

See this blog post. Basically:

// Using below code we can print any document
ProcessStartInfo info = new ProcessStartInfo(txtFileName.Text.Trim());
info.Verb = "Print";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
Matt
  • 74,352
  • 26
  • 153
  • 180
Dave
  • 341
  • 1
  • 4
  • 13