Printing using Microsoft Word Automation

Printing using Microsoft Word Automation

  
Hello all,

Recently I had to print a screen directly from the HubServer to a network printer. The point was to have the application trigger the printing automatically.

One possible solution for this problem was to use Word Automation:
1. Open the url as a word document (that is rendered inside word)
2. Trigger the print command (PrintOut method)

The result was that the word process hanged indefinitely.

After some research I managed to find that if you don’t specify a printer name (even dough it's optional) it will hang :) So, the solution is to specify the printer name, i.e, this is the answer for (1) printing from word and (2) printing from word to a specified printer.


Here is a code sample:
// Create an instance of Word and make it invisible.
wrdApp = new Word.Application();
wrdApp.Visible = false;
wrdApp.ActivePrinter = ssPrinter;
//get tem filenames
object fileName = ssUrl;
wrdDoc = wrdApp.Documents.Open (ref fileName, ref oMissing,ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
wrdDoc.PrintOut(ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing);

wrdApp.Quit(ref oFalse, ref oMissing, ref oMissing);
wrdApp = null;
wrdDoc = null;