For the needs of a project, i want to print over the LPT1 in specific locations, this will print a document in a dot matrix printer where i should print values in the places they should go. I really hate going back, and i don't have any idea where to start. Internet has no specific information about printing in LPT port with C# and especially how to send the values in specific locations while printing. Is there any good example? tutorial for this? would be a life savior.
-
Are there actually consumer systems sold today that still have parallel ports? – Anon. Jan 26 '10 at 01:09
-
2Unfortunately, there are still business documents need to be printed in those printers :( But actually this is happening to support the old way too.... – George Taskos Jan 26 '10 at 01:18
4 Answers
I could suggest one thing to make your life easier, install a generic text printer driver (this comes as standard) and set that to the LPT1 port. Then you can simply open 'LPT1' and send escape code sequences to specify font type (bold/italic), emphasized, font pitch etc. I don't know if the resources would be required. But I would imagine it would be something like this:
using (System.IO.StreamWriter sr = new System.IO.StreamWriter(@"\\.\LPT1"))
{
sr.Write(0x1b);
sr.Write('k');
sr.Write('1');
sr.Write("Hello"); // print in Sans Serif
sr.WriteLine();
sr.Flush();
}
Resources:
- Printing to a zebra printer using VB.NET (This can be easily translated to C# or compile it to a DLL and reference it in your C# project)
- An article on MSDN on how to interface to LPT1
- Here is an extensive list of info pertaining to Parallel Port. (look further down near the section titled 'Programming Tools for Port I/O and Interrupts'), discussing the usage of this DLL called inpout32.
- Here is another article on MSDN that shows how to do raw printing.
Edited @ 2017-07-12: Updated the Parallel Port link to use the Wayback Archive Machine.

- 52,284
- 6
- 19
- 43

- 34,087
- 8
- 78
- 110
-
[Parallel Port link](http://www.lvr.com/parport.htm) no longer shows what you're describing in your answer. Do you have a similar link source? – Mauricio Arias Olave Jul 12 '17 at 14:14
-
@MauricioAriasOlave: Updated the link, surprised you did not think of using the wayback machine. – t0mm13b Jul 12 '17 at 22:49
Doesn't the printer in question have a windows print driver? If so, it doesn't matter that it is printing over LPT1 or not, it is just using the standard Print stuff.
Similar question: Dot Matrix printing in C#?

- 1
- 1

- 7,668
- 4
- 33
- 50
-
You mean i could just create a Report and send it to that printer? – George Taskos Jan 26 '10 at 01:19
-
If you have a printer driver for the printer (i.e., it shows in in Control Panel/Devices as a printer), yes. Most printers have a generic compatibility mode that will allow them to be used even if you don't have an exact model number match. – Donald Byrd Jan 26 '10 at 23:04
-
1This makes printing of invoices 500% times slower, as it prints text as an image. – Vedran Aug 29 '12 at 08:07
If your printer has drivers for Windows, then you can use standard printing techniques. See Petzold's book Programming Microsoft Windows with C# for a good intro.

- 11,926
- 4
- 34
- 51
Hey I just got a dot matrix printer in 2019 and you can still buy the ribbons for £5.
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
public class ParallelPrinter
{
[DllImport("kernel32.dll", SetLastError = true)]
static extern SafeFileHandle CreateFile(string lpFileName, FileAccess dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, FileMode dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
public static void Print(string text)
{
using (SafeFileHandle fileHandle = CreateFile("LPT1:", FileAccess.Write, 0, IntPtr.Zero, FileMode.OpenOrCreate, 0, IntPtr.Zero))
{
if (fileHandle.IsInvalid == true)
throw new ApplicationException("Printer is Invalid");
using (FileStream stream = new FileStream(fileHandle, FileAccess.Write))
{
using (StreamWriter writer = new StreamWriter(stream, Encoding.ASCII))
{
writer.Write(text);
}
}
}
}
}
No drivers you just need a parallel port, you can get a PCI-e card if you don't have one.

- 131
- 4