
How to print a word document from C# app without bringing up MSWord app
I've tried that.
Here is a s{*filter*}t of code in a class, using only the System,
System.Reflection, and Word namespaces.
public bool printme()
{
ApplicationClass app = new ApplicationClass();
app.Visible = false;
object visible=false;
object fileName = "c:\\temp\\MyTest.doc";
object optional=Missing.Value;
_Document doc = app.Documents.Open(ref fileName,ref optional,ref
optional,ref optional,ref optional,ref optional,ref optional,ref
optional,ref optional,ref optional,ref optional,ref visible,ref optional,ref
optional,ref optional);
object first=0;
object xcopies = 1;
object xpt = false;
doc.PrintOut(ref optional,ref optional,ref optional,ref optional,ref
optional,ref optional,ref optional,ref xcopies,ref optional,ref optional,ref
optional,ref optional,ref optional,ref optional,ref optional,ref
optional,ref optional,ref optional);
object saveChanges = false;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
return true;
Quote:
}
When I run this I get the following error on the doc.PrintOut call, which
leaves WinWord process running in the backgroud.
***
An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in PrintWordExample.exe
Additional information: This method or property is not available because a
document window is not active.
***
Now, if I set visible to true it all works fine and dandy. I'd like for this
to all run without anything being visible though.
Anyone have insight ?
--jimmie
Quote:
> Try:
> WordApplication.Visible = false;
> > Could anyone give some insight on how I could print a word document from
a
> > C# app without actually bringing up MS Word application ? Basically, I
> want
> > to have a print server (in C#) that listens for documents. I can print
> > Crystal reports just fine and I can print Word documents, but, the
> > application always pops up. Is there a word API or Com object that will
> > allow me to use the printing features without bringing up the
application
> ?
> > Thanks !
> > -- jimmie