views:

2376

answers:

4

Is it possible to automate the following: referencing MS Word Viewer to open a document programatically and then print it? C# ideally

Im guessing if it is possible to open it then more than likely it will be possible to print it.

I've tried adding a reference to COM Object in Visual Studio .. MS Office 11 / 12 Object Library but MS Word Library isnt listed? any ideas?

I havnt got Office 200x installed

cheers

+2  A: 

We did it by using the Word Interop assembly. This requires Word to be installed (launches a WINWORD process behind the scenese) and the interop allows you to interact with it in your code.

As far as I know, that is the only way to do it.

Russell
+1  A: 

Are referring to the free Microsoft Word Viewer, which allows you to view Word documents without actually having Word installed? If so, I don't believe there is a way to automate the viewer since it doesn't install the Word COM automation libraries, which is what you would need.

Scott Dorman
Sometimes programs support another way, e.g. DDE or a command-line parameter, to tell them to print something. You may see that in the registry, e.g. in my `HKEY_CLASSES_ROOT\AcroExch.acrobatsecuritysettings.1\shell\Print\command` I have a value ""C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"" /p /h "%1" ... where the /p parameter is presumably telling it to print.
ChrisW
A: 

Have a look here: http://support.microsoft.com/kb/311452/en-us

DmitryK
This isn't relevent to the "MS Word Viewer", is it?
ChrisW
This is relevant to Visual Studio and loading proper libraries (with examples)
DmitryK
A: 

Try Aspose.Words, it's designed to allow for Office automation without any dependencies on having Word installed. It provides a nice API to open the document then perform a range of actions such as print, export to pdf and many other outcomes.

Brian Scott