Reputation: 26057
I am trying to figure out if it is possible to create a custom print port in .NET. Functionality I am trying to achieve is to intercept data generated by printer driver and send it to a remote server instead of device.
Upvotes: 4
Views: 6697
Reputation: 2140
You can also make use of the multi file port by installing the mfilemon which is a free utility. With the help of this port you can direct the output of a printer to a folder of your wish and then u can start your application too.
Upvotes: 0
Reputation: 57593
Yes, it is. I've done it in C#, writing a PDF printer controlled by software.
Steps to achive your goal are:
Here is a bunch of code for your custom application:
string fname = Environment.GetEnvironmentVariable("TEMP") + @"\";
fname += DateTime.Now.ToString("yyyyMMdd-hhmmss-fffff") + ".ps";
FileStream fs = new FileStream(fname, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
StreamReader sr = new StreamReader(Console.OpenStandardInput());
sw.Write(sr.ReadToEnd());
sw.Flush();
sw.Close();
sr.Close();
I edit my post to answer your comment:
Upvotes: 6
Reputation: 283911
Not really. Either creating a virtual port driver or a network redirector requires native code. However...
You could capture the data by installing a network print port and implementing the server side in .NET. For example, LPR would require you to create a TCP socket server, and that's completely feasible to do in C#.
I don't know of any existing C# implementation, but you could learn a lot from the source code of p910nd.
Upvotes: 1