Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my project there is a requirement , to print any type of documents to provided printer on server side. 1. My application hosted on IIS server. 2. From client side i.e. from UI request initiate for printing to web API. 3. As application is hosted in IIS .net ProcessStart option not working. Also not allowed to change application pool identity and its rights so that this idea dropped.

Please provide/suggest me the alternative solution for mentioned scenario.

What I have tried:

I tried .net system.Diagnostic Process class to print files using PrintTo verb.
But my application is hosted in IIS so unable to achieve it.
Posted
Updated 30-Apr-18 10:05am
Comments
Mehdi Gholam 30-Apr-18 13:14pm    
For each extension you need software on your server that recognizes and can print it. Try looking into components that do this.
SURAJ-CDAC 30-Apr-18 14:25pm    
I have all software i.e. MS WORD ,Acrobat reader, Notepad , Wordpad , mspaint etc.
Is there any generic solution to achieve this
Richard Deeming 30-Apr-18 13:21pm    
You're printing from the server, so the printer needs to be connected to the server.

If you're trying to print to the client's printer, then it's not going to work.
SURAJ-CDAC 30-Apr-18 14:22pm    
Yes i m printing from server. Also all printers are connected to the server.
Is there any generic solution to achieve this

Of course printing from the server side for the client is involves a very complicated printer selection (even server can access all printers), but I leave that for you (And I not even mention how wrong is to have a server with all those UI based tools installed on)...
When you right click a file in Explorer you - mostly - get a Print/Print To option somewhere next to Open...
Explorer can add that menu item based on info stored in the registry for each and every extension (file type)...
You can do the same...
For instance if you have a .txt (text) file you can go to the registry and retrieve the print command to print that file...
C#
string szExt = Registry.GetValue("HKEY_CLASSES_ROOT\\" + ext, string.Empty, null);
string szPrintTo = Registry.GetValue(string.Format(@"HKEY_CLASSES_ROOT\{0}\shell\Printto\command", szExt), string.Empty, null);

All you have to do is replace the parameters (%1, %2) with your files and execute the command (using Process)...
 
Share this answer
 
This isn't going to be practical at all, and in some cases, impossible to do.

In order to print all of those files, you would need software installed on the server that can read and render every format of those files you want to support.

Some of those extensions will only print from Microsoft Office, which you can NOT use from a web server, or any other unattended process, like a Windows Service.

There is no generic method for printing any file type you want! You either have the software to print each specific file type or you don't print it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900