locked
Printing in Dot Matrix native fonts

    Question

  • Dear All,

    I am really having hard time to find a solution for below stated problem.

    All I want to do is Print using a Dot Matrix Printer. But I want the printer to use its native font setting rather than using windows fonts. For e.g. when I simply go to command prompt and use 'print' command to send a text file to LPT1, its printed in native printer fonts (there are 5-6 font selection on printer itself). But no matter how I print through VB, it always uses the windows fonts.

    As a temporary solution, I am first creating a text file with required data and then executing an external command prompt 'print' command with this text file path to send it in 'raw' format to the printer. This is working but poses several challenges for e.g I cannot use scaling, page break etc. things.

    The reason why I need this is because the printer, when using native fonts, prints very fast and character formation is pure dot-matrix based. Windows fonts like Arial are printed as a graphic with repeated strokes of the printer head.

    The printer I am using is TVSE Gold Champ (available in India), but its only a dot matrix for that purpose.

    Currently I am programming in Visual Basic 2008 Express Edition.

    Any help will be highly appreciated.

    Kr

    Prashant

    Saturday, May 01, 2010 3:21 PM

All replies

  • Hi Prashant,

    I'm sorry I don't have the solution for you! I have the same problem and I was wondering if you ever solved the problem? If so I'd love to hear how you did it.

    Regards,

    Jim.

    Thursday, September 16, 2010 9:29 AM
  • Hi Jim,

    No, I am still looking for a solution.

    Regards,

    Prashant

    Sunday, September 26, 2010 6:37 PM
  • try this

    cheers,

    John

    Friday, October 15, 2010 9:29 PM
  • An easy way offers following code:
    
    Possibility 1:
    
    Private Sub DruckenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DruckenToolStripMenuItem.Click
        'Einfachste Druckmethode die direkt ohne Druckerauswahlmenü mit dem Standarddrucker druckt
        'PrintDocument1.Print()         '// wegen komfortableren Code hier auskommentiert
        
    
        'Nachdem der PrintDialog der Form hinzugefügt wurde, sieht der Code so aus
        If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
          PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
          PrintDocument1.Print()
        Else : End If
    
    
    
    Possibilty 2 (choose either one or two)
    
    
    A very comfortable dialog for more pages, look here:
    
    
    Use:
    
    Imports System.Drawing.Printing ' absolutely necessary for multipage prints
    Imports System.IO
    
    
    Private Sub Druck(ByVal sender As Object, ByVal e As PrintPageEventArgs) _
      Handles doc.PrintPage
        Try
          Dim ft As Font = Textfenster.Font
          'Dim ftKopf As Font = New Font("Arial", 10, FontStyle.Regular)
          'e.Graphics.DrawString(Message, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 40, 100)    '40Punkt linke Blattrand 100 Punt von oben
          Dim foreBrush As Brush = New SolidBrush(Textfenster.ForeColor)
          Dim form As New StringFormat()
          Dim außen, innen As RectangleF
          Dim zeichen, zeilen As Integer
    
          'umschreibendes Rechteck des Druckbereichs mit/ohne Kopfzeile
          außen = e.MarginBounds
          innen = RectangleF.Inflate(außen, 0, -2 * ft.GetHeight(e.Graphics))
    
          'Anzahl vollständig passender Druckzeilen ermitteln und Höhe anpassen
          Dim anzahlZeilen As Integer = innen.Height \ ft.GetHeight(e.Graphics)
          innen.Height = anzahlZeilen * Textfenster.Font.GetHeight(e.Graphics)
    
          'Seite drucken (automatisch abgeschnitten durch form)
          If nummer >= von AndAlso zuDrucken.Length >= 0 Then
            'zu langen Text hinter dem Wort anpassen/umbrechen
            form.Trimming = StringTrimming.Word
            e.Graphics.DrawString(zuDrucken, ft, foreBrush, innen, form)
    
            'Dateiname in der Kopfzeile anzeigen
            form.Alignment = StringAlignment.Center
            e.Graphics.DrawString(Text, ft, foreBrush, außen, form) '//Gleiche Schriftart und Farbe wie der Rest
            'e.Graphics.DrawString(Text, ftKopf, Brushes.Black, außen, form)
            
            
            'Seitennummer rechtsbündig in Fußzeile anzeigen
            form.Alignment = StringAlignment.Far
            e.Graphics.DrawString("S " & nummer, ft, foreBrush, außen, form) '//Gleiche schrift und Farbe wie der Rest
            'e.Graphics.DrawString("S " & nummer, ftKopf, Brushes.Black, außen, form)
            'e.Graphics.DrawString(Text, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, außen, form)    '40Punkt linke Blattrand 100 Punt von oben
    
          End If
    
          'Gedruckten Text aus Drucktext nehmen; zeichen:zeilen: Größe der Seite
          form.Trimming = StringTrimming.Word
          e.Graphics.MeasureString(zuDrucken, ft, innen.Size, form, zeichen, zeilen)
          zuDrucken = zuDrucken.Substring(zeichen)
          nummer += 1
          ' If nummer - 1 > von Then
          'Druck(sender, e)
          'Else
          e.HasMorePages = zuDrucken.Length > 0 AndAlso nummer <= bis
          'End If
          foreBrush.Dispose() 'Gibt den Brush wieder frei
        Catch ex As Exception
    
        End Try
    
    
    Private Sub DruckenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DruckenToolStripMenuItem.Click
    
        Dim d As New PrintDialog() : d.Document = doc : d.AllowSomePages = True
        If d.ShowDialog() = DialogResult.OK Then
          doc.DocumentName = Text & " " & Now
          zuDrucken = Textfenster.Text
          Select Case d.PrinterSettings.PrintRange
            Case PrintRange.AllPages
              von = 1 : bis = d.PrinterSettings.MaximumPage
            Case PrintRange.SomePages
              von = d.PrinterSettings.FromPage : bis = d.PrinterSettings.ToPage
          End Select
          nummer = 1
          doc.Print()
        End If
    
      End Sub
    
    Excuse the German comments. They are much easier for me to write and understand than English.
    
    


    Liebe Grüße Stefan | Cheers Stefan I'm using VB 2008 Express
    Friday, October 15, 2010 10:56 PM
  • Try This Code

    open "lpt1" for output as #1

    print #1, "whatever you need to print"

    print #1, "whatever you need to print"

    print #1, "whatever you need to print"

    print #1, chr$(12) ' page break character

    close #1

    • Proposed as answer by Anand.Thomas Saturday, December 15, 2012 9:38 AM
    Saturday, December 15, 2012 9:38 AM