c# - Print to Network (Shared) Printer - Word Interop -


i need print word document on server side network printer. web page sends document , file location server open , replace mail merge items , print document preferred (not default) network printer. preferred printer name changes when document selected on web page changes

i'm using word 14.0 object library, asp.net mvc 4.0, .net framework 4.0, iis 7 on windows server 2008 r2. on iis created app pool runs on specific account identity (accountname@domainname). load user profile set true load network printer connections in registry. allowed account have permissions run word com interop services. successful open document , replace mail merge fields , save pdf send file attachment email.

the word application has default printer in activeprinter property, print default printer well. final goal print word preferred network printer before close word application , active document.

the following 2 methods causing exceptions if try change activeprinter property.

word.application wordapp = new word.application(); 

first method:

wordapp.activeprinter = "preferredprintername";  

second method;

object[] oworddialogparams = { "\\<servername>\<printername>", true }; string[] argnames = { "printer", "donotsetassysdefault" }; object wordbasic = wordapp.wordbasic;  wordbasic.gettype().invokemember("fileprintsetup"            , system.reflection.bindingflags.invokemethod            , null            , wordbasic            , oworddialogparams            , null            , null            , argnames); 

i found word application object not loading printers installed user account. loads default printer. i'm assuming reason exceptions when above 2 methods attempting change or add preferred printer application object because printer i'm trying set never found in active printers list.

how installed shared printers under user profile loaded in word application object?

using office interop in server-scenario (like asp.net, windows service etc.) not supported ms - see http://support.microsoft.com/default.aspx?scid=kb;en-us;q257757#kb2

additionally there have been several security-related changed since windows vista make hard "desktop-like" in windows service (iis/asp.net special case of windows service in regard).

another point "printing" server-scenario cause problems since iis (special) windows service... windows service don't have "full/real" desktop in turn needed printing robustly...

i don't think there easy solution scenario...

i break down different components:

  • word document handling (for example aspose.words)
  • create pdf resulting word file (for example aspose.words)
  • implement hotfolder on target network printer
  • copy pdf on hotfolder printing

this robust , supported option scenario...


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -