I am trying to use Word.Interop to print from ASP.NET. I can get it to
open the document but it just hangs on the PrintOut method. I have
tried a variety of combinations for the arguments (background = false
etc.) to no avail.
The code example is as below:
------------------------------------------------------
private static void PrintDoc(string docName, string path)
{
string fileName = path + string.Format("{0}.doc",docName);
ApplicationClass app=new ApplicationClass();
object background = true;
object oFalse = false;
object oTrue = true;
object oOne = 1;
object missing = System.Reflection.Missing.Value;
object file=fileName;
Document doc2 = app.Documents.Open(ref file,ref missing,ref
missing,ref missing,
ref missing,ref missing,ref missing,ref missing,ref missing,
ref missing,ref missing,ref oTrue,ref missing,ref missing,ref
missing);
doc2.PrintOut(ref background,ref oFalse,ref missing,ref missing,ref
missing,ref missing,
ref missing,ref oOne,ref missing,ref missing,ref oFalse,ref
missing,ref missing,
ref missing,ref missing,ref missing,ref missing,ref missing);
doc2.Close(ref missing, ref missing, ref missing);
}
------------------------------------------------------
Any ideas would be great!
Cheers,
Brett
Claus Nielsen - 06 Jan 2005 12:52 GMT
Hello Brett
I'm guessing that you are using C#, since I can compile what you just sent.
I tried to convert a VBA script:
/*
* VB:
* Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
* wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
* ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
* False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
* PrintZoomPaperHeight:=0
*/
To C#:
object Background = true;
object Append = false;
object Range = Word.WdPrintOutRange.wdPrintAllDocument;
object OutputFileName = "";
object From = Type.Missing;
object To = Type.Missing;
object Item = Word.WdPrintOutItem.wdPrintDocumentContent;
object Copies = 1;
object Pages = "";
object PageType = Word.WdPrintOutPages.wdPrintAllPages;
object PrintToFile = false;
object Collate = true;
object ActivePrinterMacGX = Type.Missing;
object ManualDuplexPrint = false;
object PrintZoomColumn = false;
object PrintZoomRow = false;
object PrintZoomPaperWidth = false;
object PrintZoomPaperHeight = false;
oDoc.PrintOut(ref Background, ref Append, ref Range, ref OutputFileName,
ref From, ref To, ref Item, ref Copies, ref Pages, ref PageType,
ref PrintToFile, ref Collate, ref ActivePrinterMacGX, ref ManualDuplexPrint,
ref PrintZoomColumn, ref PrintZoomRow, ref PrintZoomPaperWidth,
ref PrintZoomPaperHeight);
.. However you should know that I'm using Office 2003, so what version are
you using?
Try to populate all the arguments in the PrintOut method, to see if that
helps.
I even tried just printin the page in VBA, but it left out all arguments, so
I suppose that you could try typing in Type.Missing in all arguments, and
see what happens...
Hope this helps!
Regards
Claus Nielsen
>I am trying to use Word.Interop to print from ASP.NET. I can get it to
> open the document but it just hangs on the PrintOut method. I have
[quoted text clipped - 39 lines]
> Cheers,
> Brett
Brett Raven - 06 Jan 2005 21:49 GMT
Hi, thanks for the reply.
Yeah it is in C# - I figured VBA was not part of the dotnet newsgroup
but who knows nowadays with the new vesion of Office supporting managed
code.
Anyway, I have solved the problem. I needed to set the ActivePrinter
property for the Word.Application object. Its all working fine now.
Happy new year!