This is an old revision of the document!


RedMon

Redirection Port Monitor (RedMon) is a virtual printer port that can redirect output to a file or program which can in turn process the printer data or send it to a physical printer.

Installation
Add Redirected Port (RPT1:)
  • Run cmd as Administrator.
  • Run one of these commands:
    • Add new printer: C:\> rundll32 printui.dll,PrintUIEntry /il
    • Update current printer: C:\> rundll32 printui.dll,PrintUIEntry /n “Printer Name” /p
    • Add Port: Ports (tab) > New Port > Redirected Port > Port Name: “RPT1:”
Configure Redirected Port (RPT1:)
Example

RedMon passes the original print job via STDIN to the program C:\PrinterTranslator.exe. It also passes a command line argument specifying where PrinterTranslator should save the output print job after making its changes. RedMon then takes the file and spools it directly to the selected printer, in this case Zebra TLP 3742.

PrinterTranslator is a basic program which accepts the STDIN input from RedMon, makes a few changes to the formatting and outputs the file. You can see the source code below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
 
namespace PrinterTranslator
{
  class Program
  {
	  static void Main(string[] args)
	  {
		  // Check if an output filename was provided and close if it wasn't.
		  string Filename = "";
		  if (args.Length == 0)
		  {
			  Console.WriteLine("No file was specified to write the translated data to... closing.");
			  return;
		  }
		  else
		  {
			  Filename = args[0];
		  }
 
		  bool UsingSTDIN = false;
		  string InputFile = "";
		  try
		  {
			  // This function throws an InvalidOperationException when the input is coming from STDIN.
			  UsingSTDIN = System.Console.KeyAvailable;
 
			  if (!UsingSTDIN)
				  return;
		  }
		  catch (InvalidOperationException e)
		  {
			  // Since we got this exception we know we got data from STDIN.
			  InputFile = System.Console.In.ReadToEnd();
		  }
 
		  string[] LinesToProcess = InputFile.Split('\f');
 
		  // Prep the file so we can save the fixed lines as we run through them.
		  StreamWriter OutFile = new StreamWriter(Filename);
 
		  // Fix the file formatting.
		  foreach (string Line in LinesToProcess)
		  {
			  string newLine = Line;
 
			  // Make sure all quotes are ended.
			  if (Line.Contains('"'))
			  {
				  int FirstQuote = Line.IndexOf('"');
 
				  if (FirstQuote != -1)
				  {
					  int LastQuote = Line.LastIndexOf('"');
 
					  if (FirstQuote == LastQuote)
						  newLine += '"';
				  }
			  }
 
			  // Write out the fixed line.
			  // Check if the string already contains a carriage return. 
                          // In that case, we do not want to do a WriteLine as 
                          // we will actually write 2 lines.
			  if (!(newLine == "\r\n"))
			  {
				  OutFile.WriteLine(newLine);
			  }
		  }
		  OutFile.Close();
	  }
  }
}