How to print a word document from C# app without bringing up MSWord app 
Author Message
 How to print a word document from C# app without bringing up MSWord app

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



Mon, 25 Oct 2004 05:00:41 GMT  
 How to print a word document from C# app without bringing up MSWord app
Try:
WordApplication.Visible = false;



Quote:
> 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



Mon, 25 Oct 2004 06:44:31 GMT  
 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



Mon, 25 Oct 2004 23:02:48 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. extracting text from a word document without word

2. open a Word document inside an MFC app?

3. How to Embed Microsoft Word Document without using document view architecture

4. Start an SDI App without a Document?

5. Start SDI app without new document?

6. Help! Start MDI app without document

7. Start-Up MDI app without opening empty document

8. MDI app without initial Child, but message mapped to document class

9. Parsing Msword Document with C#

10. Converting a Single Document app to a CDialog app

11. Converting a Single Document app to a CDialog app

12. MFC app without app window

 

 
Powered by phpBB® Forum Software