vb.netprintingepsondot-matrix

Print to a Dot-Matrix Printer directly from VB.NET


i am finishing a program i am writing and i have to create a printing to an Epson LQ-300+ Dot-Matrix. The printing has to print some text in some specific parts of the paper (Amount,name etc) Can anyone point me to the right direction or post me an example since i was not able to find something in order to send directly the ASCII characters to the printer via LPT1. Thank you.


Solution

  • IT Is going to be mainly trial and error a far as positioning goes, it is also going to depend on the font and wether or not you are using a Generic/Text Driver (if so the character spacing, line spacing and font are what ever the printer has been setup for). Back in the DOS days you could send out individual characters to the printer but printing in windows is page based meaning you will need to use the PrintDocument Class, handle the PrintPage event using the PrintPageEventArgs Graphic Property's PrintString Method to position the text where you need it to be.

    Something like this:

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            PrintDocument1.Print()
        End If
    End Sub
    
    Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        e.Graphics.DrawString("Hello World", New Font("Arial", 10), Brushes.Black, New Point(100, 100))
    End Sub