Lines are cut off when Printer.Print to shared text printer

I am maintaining an old vb6 application that prints ZPL-II.

I just find out that it has a bug, if I print long lines to the printer using Printer.Print "the lines will be cut to the first 89 bytes / lines. It works fine and supports lines when I use Print or Copy in DOS for LPT.

Where does this behavior come from? How can I fix this or workaround? I would like to support all printers including LPT, USB and network printer.

PS. I am double checking the actual bytes sent to the printer by printing to a file, not LPT.

0


source to share


2 answers


I worked to NOT use Printer.Print. But using FileSystemObject to print a text file to a UNC path to a network printer.



It works like a cream, but the printer needs to be mapped. Even a local printer.

0


source


You need to use the Printer.TextWidth function and compare it to the Printer.ScaleWidth property to deal with this problem in Visual Basic 6. This does not make an auto-line for you as a DOS function.

You will make sure that the font that is installed too correctly matches the font of the printer. This may require the use of one of the "generic" fonts that the driver ships with. Otherwise, try using Courier New, which is a fixed space font. Otherwise, the text width value will not correctly report the width.

An alternative is to use the Len string function to count the number of characters and handle the truncation itself if it exceeds 89 characters.

Something like



  Do Until LineToPrint = ""
    TempD = Len(LineToPrint)
    If TempD > 89 Then
      Print Mid$(LineToPrint,1, 89)
      LineToPrint = Right$(LineToPrint,TempD-89)
    Else
      Print LineToPrint
      LineToPrint = ""
    End If
  Loop   

      

If you like recursive functions, you can write it like this:

Private Sub PrintLine(ByVal LineToPrint As String, ByVal Width As Integer)
    TempD = Len(LineToPrint)
    If TempD > Width Then
      Printer.Print Mid$(LineToPrint, 1, Width)
      LineToPrint = Right$(LineToPrint, TempD - Width)
      PrintLine LineToPrint, Width
    Else
      Printer.Print LineToPrint
    End If
End Sub

      

0


source







All Articles