redirect printer output to C# application, using redmon

1.3k Views Asked by At

I'm trying to intercept the content from a redirect port (Redmon) to a C# application so I can process it. Right now I'm just trying to figure out how to pass the output into my app.. I thought I could just input it through std input, but its not working. In a coomand line I can pipe text into my application and it works, but if I try to print through a redmon port, my application doesn't seem to take the input. I set up Redmon to let my application handle the output. Here's my code and a screen shot of the printer port settings.

namespace titoprint
{
    class Program
    {
        static void Main()
        {
            int result;
            while ((result = Console.Read()) != -1)
            {
                Console.WriteLine("{0} = {1} ", result, (char)result);
            }
            Console.WriteLine("in console");
            MessageBox.Show("ok done!");
            Console.ReadLine();
        }
    }
}

`Port settings

I;m only tryint to pass text to the application also. So so the process i'm using is winprint and set to text.

Thanks

1

There are 1 best solutions below

0
On

You can read like this:

Stream content = Console.OpenStandardInput();

using (BinaryReader standardInputReader = new BinaryReader(content))
{
    using (FileStream standardInputFile = new FileStream(standardInputFilename, FileMode.Create, FileAccess.ReadWrite))
    {
        standardInputReader.BaseStream.CopyTo(standardInputFile);
    }
}

Then you can convert to PDF:

String[] ghostScriptArguments = { "-dBATCH", "-dNOPAUSE", "-dSAFER",  "-sDEVICE=pdfwrite",String.Format("-sOutputFile={0}", outputFilename), standardInputFilename };