Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have page size 8*4in(w*h) i have tried print using follwing code but unable to set font and page size i have dot matrix printer lx-310 i also tried to adjust text as per my
requirement can any body suggest me how to do that.

What I have tried:

  On Error GoTo ErrHandler
                sPath = App.Path & "\Rpt" & ".txt"
                Open sPath For Output As #1
                'Print #1, Chr$(27) & "C" & Chr$(0) & Chr$(6);
                'Address10
              '  Printer.Font.Size = "12"
               ' Printer.Font.Bold = False
               
                


                Print #1, "This is a test"  ' Print text to file.
Print #1, ' Print blank line to file.
Print #1, "Zone 1"; Tab; "Zone 2"  ' Print in two print zones.
Print #1, "Hello"; " "; "World"   ' Separate strings with space.
Print #1, Spc(5); "5 leading spaces "  ' Print five leading spaces.
Print #1, Tab(10); "Hello"  ' Print word at column 10.
 
' Assign Boolean, Date, Null and Error values.
Dim MyBool, MyDate, MyNull, MyError
MyBool = False: MyDate = #2/12/1969#: MyNull = Null
MyError = CVErr(32767)
' True, False, Null, and Error are translated using locale settings of
' your system. Date literals are written using standard short date
' format.
Print #1, MyBool; Tab; "  is a Boolean value"
Print #1, MyDate; " is a date"
Print #1, MyNull; " is a null value"
Print #1, MyError; " is an error value"

Print #1, MyBool; " is a Boolean value"
Print #1, MyDate; " is a date"
Print #1, MyNull; " is a null value"
Print #1, MyError; " is an error value"

Close #1 ' Close file.
Posted
Updated 26-Nov-20 13:23pm
Comments
Richard MacCutchan 26-Nov-20 15:10pm    
You need to check the documentation for the printer to find out how to change the settings.
Member 13129983 27-Nov-20 6:59am    
i have created text file and printer page size is also set to 8*4 but i am unable to bold and change font size in file and also the margin's
The Other John Ingram 26-Nov-20 22:17pm    
You need the control codes to do this
Find the make and model of the printer and search the web for the control codes
Embed the control codes in your program
Member 13129983 27-Nov-20 6:59am    
i have created text file and printer page size is also set to 8*4 but i am unable to bold and change font size in file and also the margin's

1 solution

I don't see where in your code you're addressing a printer at all - writing to a printer directly would likely involve sending commands to a COM port (or virtual com port)

This https://files.support.epson.com/pdf/general/escp2ref.pdf shows all the available commands - for your printer it is likely the '9-Pin ESC/P' commands that will be useful

Once you have identified to which COM port your printer is connected, then you do

Open "COM1" For Output As #1
 
Print #1, Chr$(&H1B); "@"; 'Initializes the printer (ESC @)
Print #1, Chr$(&H1B); "a"; Chr$(1); 'Specifies a centered printing position (ESC a)
Print #1, Chr$(&H1B); "!"; Chr$(0); 'Specifies font A (ESC !)
Print #1, "January 14, 2002 15:00";
Print #1, Chr$(&H1B); "d"; Chr$(3); 'Prints and 3 line feeding (ESC d)
Print #1, Chr$(&H1B); "a"; Chr$(0); 'Selects the left print position (ESC a)
Print #1, Chr$(&H1B); "!"; Chr$(1); 'Selects font B
Print #1, "TM-U210B $20.00"; Chr$(&HA);
Print #1, "TM-U210D $21.00"; Chr$(&HA);
Print #1, "PS-170 $17.00"; Chr$(&HA);
Print #1, Chr$(&HA); 'Line feeding (LF)
Print #1, Chr$(&H1B); "!"; Chr$(17); 'Selects double-height mode
Print #1, "TOTAL $58.00"; Chr$(&HA);
Print #1, Chr$(&H1B); "!"; Chr$(0); 'Cancels double-height mode
Print #1, "------------------------------"; Chr$(&HA);
Print #1, "PAID $60.00"; Chr$(&HA);
Print #1, "CHANGE $ 2.00"; Chr$(&HA);
Print #1, Chr$(&H1D); "V"; Chr$(66); Chr$(0); 'Feeds paper & cut
 
Close #1
 
Share this answer
 
Comments
Member 13129983 27-Nov-20 6:54am    
i have created text file and printer page size is also set to 8*4 but i am unable to bold and change font size in file and also the margin's

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900