Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

vb.net - 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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...