vb.nettextprintingdot-matrix

How to print a text file in Dot Matrix printer using chr values?


I tried printing a file in dot matrix printer (Wipro (wep) EX 330+dx) using doc, rtf, pdf, xlsx formats exported from crystal reports but the process printing is very slow.
I was trying to print a bill but bill takes time of approx 50-60 sec.

I even tried transferring file to text via crystal reports but it didn't help.

So, one of my colleague shows me a method of printing it through a text file and he is using commands such as chr(14) & "TITLE NAME HERE" & chr(27) & chr(18) . It writes in the text file like TITLE NAME HERE with some special characters in the text file but when we print it using a bat file the characters TITLE NAME HERE gets big and bold print in dot matrix printer and the special character vanishes in printing. Moreover, the print is speedy. I guess the special characters works like tags in HTML for text file.

So, my question is that is there any guide of these characters and how do they work?
What character gives which effect on print and all stuff?


Solution

  • The conclusion of the discussion of this question, for now, is crystal report printing is slower than a text file in a dot matrix printer.
    So if we talk for generating a report in a text file,
    Following are some variables given by my colleague which eases to generate reports in a text file.

    '---------------------------------------------DOT MATRIX PRINTER VARIABLES-----------------------------------------------------------------------
    Dim es = Chr(27)
    Dim eject = Chr(12)
    Dim bx1 = Chr(176)
    Dim bx2 = Chr(177)
    Dim bx3 = Chr(178)
    Dim bx4 = Chr(219)
    Dim ebig1 = Chr(14) & Chr(27) & "w1" & Chr(27) & "G" 'extra large
    Dim ebig2 = Chr(27) & "w0" & Chr(27) & "H" & Chr(18) 'extra large
    Dim emf1 = es & "E"             ' Select Emphasize Mode
    Dim emf2 = es & "F"             ' Cancel Emphasize Mode
    Dim ita1 = es & "4"             ' Select Italic Mode
    Dim ita2 = es & "5"             ' Cancel Italic Mode
    Dim uln1 = es & "-1"            ' Turn Underlining On
    Dim uln2 = es & "-0"            ' Turn Underlining Off
    
    'Commented variables are for small column printers like Epson printers
    'Dim chr1 = Chr(27) & "(s10H"
    'Dim chr2 = Chr(27) & "(s10H"
    'Dim cnd1 = Chr(27) & "(s16.5H"
    'Dim cnd2 = Chr(27) & "(s10H"
    'Dim big1 = Chr(27) & " "
    'Dim big2 = Chr(27) & " "
    'Dim stk1 = Chr(27) & "(s5H"
    'Dim stk2 = Chr(27) & "(s10H"
    
    Dim chr1 = es & "M"            ' Select 12 Pitch"
    Dim chr2 = es & "P"            ' Select 10 Pitch
    Dim big1 = es & "W1"           ' Select Double-width Mode(one line)"
    Dim big2 = es & "W0"           ' Cancel Double-width Mode(one line)"
    Dim cnd1 = Chr(15)             ' Select Condensed Mode
    Dim cnd2 = Chr(18)             ' Cancel Condensed Mode
    Dim stk1 = es & "G"            ' Select Double-strike Mode
    Dim stk2 = es & "H"            ' Cancel Double-strike Mode
    '------------------------------------------------------------------------------------------------------------------------------------------------
    

    Direct printing a text file to dot matrix printer might won't work.
    Note: Run the text file using bat file to work.
    This is how I created a report in a text file. Some of the variable declarations not shown here.

    stringToPrint = Nothing
        Dim Repline As String = String.Join("", Enumerable.Repeat("=", 80)) ' 
        A LINE CREATED WITH 80 '=' character to show a visible linefeed
    
        stringToPrint = chr2 & Environment.NewLine & big1 & PubCName & big2 & Environment.NewLine
        stringToPrint = stringToPrint & Left$(PubCAdd, 30) & Space(IIf(PubCAdd.Length > 30, 0, 30 - PubCAdd.Length)) & Space(5) & "GST NO./PAN NO." & Space(1) & PubGSTNo & Environment.NewLine
        stringToPrint = stringToPrint & Left$(PubCAdd2, 30) & Space(IIf(PubCAdd2.Length > 30, 0, 30 - PubCAdd2.Length)) & Space(5) & "PHONE NO." & Space(1) & PubCPh1 & Environment.NewLine
        stringToPrint = stringToPrint & PubCCity & "-" & Space(1) & PubPinCode & Space(10) & big1 & "***TAX INVOICE***" & big2 & Environment.NewLine
        stringToPrint = stringToPrint & Repline & Environment.NewLine
    

    I generated a bat file say Print.bat. The code inside bat file is

    @echo off
    type fileaddresshere > prn
    exit
    

    fileaddresshere includes whole address along with the extension. Example: D:\TextPrint.txt
    I am not aware of the last special character in the code above but will update the answer as soon as I get it.

    Please feel free to give suggestion for this answer. Even I am trying these codes and watching its effect in print for now so all is trial and error for me.