473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

changing printer fonts

Hi,

I need to change the printer's font to "control" -a printer font, and then
send a sequence of characters to the printer. My problem is that I cannot
change the printer's font. Can this be done without API calls?

Thanks
Ioannis
Nov 20 '05 #1
6 10451
"Ioannis Demetriades" <id**********@yahoo.co.uk> wrote in message
news:Oe*************@TK2MSFTNGP11.phx.gbl...
Hi,

I need to change the printer's font to "control" -a printer font, and then
send a sequence of characters to the printer. My problem is that I cannot
change the printer's font. Can this be done without API calls?


Not that I know of. Printing is too abstracted in .NET, relying on the
graphics and drawing namespaces mostly for rendering type. As a result you
can only access OpenType and TrueType fonts for sending to the printer.

You would have to import and call winspool.drv to gain any real direct
access to the spooler via .NET.

R.
Nov 20 '05 #2
If you are using PrintDocument then you need to render the string of
characters using the Graphis object that's passed into your PrintPage Event
Handler.

e.Graphics.DrawString( sString, <Your Font>,.....)
Nov 20 '05 #3
If I understand what you are doing - you are probably working with some sort
of receipt printer and maybe trying to pop a cashdrawer or something to that
effect. There should be codes associated with your printer that you can
send to it and do this

You'll need to go unmanaged to do this, and it's probably specific to that
printer to some degree, unless you are using some standard POS codes.
Instead of trying to set your font under windows to control, you'll want to
send the appropriate escape char to set it.

Check out KB 322090:

http://support.microsoft.com/default...en-us%3B322090

--
Justin Weinberg

Designing a PrintDocument? Drawing to forms?
Check out GDI+ Architect at www.mrgsoft.com
"Ioannis Demetriades" <id**********@yahoo.co.uk> wrote in message
news:Oe*************@TK2MSFTNGP11.phx.gbl...
Hi,

I need to change the printer's font to "control" -a printer font, and then
send a sequence of characters to the printer. My problem is that I cannot
change the printer's font. Can this be done without API calls?

Thanks
Ioannis

Nov 20 '05 #4
* "Ioannis Demetriades" <id**********@yahoo.co.uk> scripsit:
I need to change the printer's font to "control" -a printer font, and then
send a sequence of characters to the printer. My problem is that I cannot
change the printer's font. Can this be done without API calls?


How do you print to the printer? Is it a "normal" printer?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
Hi Justin,

What i am trying to do is to instruct a POS printer to open the cash drawer.
The appropriate escape sequence is just a single character -the problem is
that i have to change the font of that char just before sending it. I've
tried it in VB6 and it works!.

Is there a way to substitute the changing of the font with a sequence of
characters?

Thanks
"Justin Weinberg" <jweinberg@_spamkill_mrgsoft.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
If I understand what you are doing - you are probably working with some sort of receipt printer and maybe trying to pop a cashdrawer or something to that effect. There should be codes associated with your printer that you can
send to it and do this

You'll need to go unmanaged to do this, and it's probably specific to that
printer to some degree, unless you are using some standard POS codes.
Instead of trying to set your font under windows to control, you'll want to send the appropriate escape char to set it.

Check out KB 322090:

http://support.microsoft.com/default...en-us%3B322090

--
Justin Weinberg

Designing a PrintDocument? Drawing to forms?
Check out GDI+ Architect at www.mrgsoft.com
"Ioannis Demetriades" <id**********@yahoo.co.uk> wrote in message
news:Oe*************@TK2MSFTNGP11.phx.gbl...
Hi,

I need to change the printer's font to "control" -a printer font, and then send a sequence of characters to the printer. My problem is that I cannot change the printer's font. Can this be done without API calls?

Thanks
Ioannis


Nov 20 '05 #6
Yes. They are called "Escape characters" because they are non printable
characters. When the printer gets one, it interprets it as a command
instead of as output text.

This code is from my POS system bravopos (see www.bravopos.com). Verified
working (we've been testing for like two years because I can't figure out
what to do with it hehe).

It's in VB6, but it should give you a clear starting point to PInvoke from,
because the process is the same. My target printer set was the Star line of
printers. I haven't tried it on anything else, but I have verified it works
under Star. This COM+ object sits on a Win2K server and directs output
appropriately to printers.

Note that the pop command is coming from the server in this example.

The "meat" of the code you will need is in the exec_POSCommand. You'll
notice I went through some of the same problems you are going through,
because in the database I'm storing a "control char" and then translating it
to the appropriate escape code sequence. If you have multiple cash drawers,
you can set them to respond differently A, B... etc.

If you have trouble converting it to .NET, please let me know and I'll lend
a hand.


'---------------------------------------------------------------------------
----
' File Name cCashDrawer.c
'
' Description Business Object that handles all Cash Drawer operations
'
'
' Comments
'
'
'
'
'
'
'
' Date Modified
'---------------------------------------------------------------------------
----
' 01/10/2002 Justin Weinberg Class Created
'---------------------------------------------------------------------------
----

Private Const THIS_MODULE = "BOCashDrawers.cCashDrawer"
Private Const sBravoTempConnect = "File Name=c:\Bravo\UDL\BravoTemp.udl"

Public Enum EnumCashDrawerErrors
ePrinterNotFound = vbObjectError + 1024
End Enum

Public Type DOCINFO
pDocName As String
pOutputFile As String
pDatatype As String
End Type

Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long

Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long

Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long

Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
ByVal pDefault As Long) As Long

Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
"StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
pDocInfo As DOCINFO) As Long

Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long

Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
pcWritten As Long) As Long

Private Declare Function Escape Lib "Gdi32" (ByVal hDC As Long, ByVal
nEscape As Long, _
ByVal ncount As Long, ByVal indata As String, ByVal oudata As Any)
As Integer

Private Sub exec_POSCommand(sPrinter As String, sControlChar As String)
Dim lhPrinter As Long
Dim lReturn As Long
Dim lpcWritten As Long
Dim lDoc As Long
Dim sControlString As String
Dim DocInfo_Drawer As DOCINFO

On Error GoTo common_error

Select Case sControlChar
'Control char and Hexadeciaml ESC/POS printer codes

Case "A" ' \x1B \x07 \x05 \x05 \x07 --> &H1b &H07 &H05 &H05 &H07
sControlString = Chr(&H1B) & Chr(&H7) & Chr(&H5) & Chr(&H5) & Chr(&H7)

Case "B" '\x1B \x07 \x0A \x0A \x07 --> &H1b &H07 &H0A &H0A &H07
sControlString = Chr(&H1B) & Chr(&H7) & Chr(&HA) & Chr(&HA) & Chr(&H7)

Case "C" '\x1B \x07 \x0F \x0F \x07 --> &H1b &H07 &H0F &H0F &H07
sControlString = Chr(&H1B) & Chr(&H7) & Chr(&HF) & Chr(&HF) & Chr(&H7)

Case "D" '\x1B \x07 \x14 \x14 \x07 --> &H1b &H07 &H14 &H14 &H07
sControlString = Chr(&H1B) & Chr(&H7) & Chr(&H14) & Chr(&H14) & Chr(&H7)

Case "E" '\x1B \x07 \x19 \x19 \x07 -> &H1b &H07 &H19 &H19 &H07
sControlString = Chr(&H1B) & Chr(&H7) & Chr(&H19) & Chr(&H19) & Chr(&H7)

Case "d" '\x1A --> &H1A
sControlString = Chr(&H1A)

End Select

lReturn = OpenPrinter(sPrinter, lhPrinter, 0)

If lReturn = 0 Then
Err.Raise ePrinterNotFound, Err.Source, Err.Description
Exit Sub
End If

With DocInfo_Drawer
.pDocName = "CashPop"
.pOutputFile = vbNullString
.pDatatype = vbNullString
End With

lDoc = StartDocPrinter(lhPrinter, 1, DocInfo_Drawer)
lDoc = StartPagePrinter(lhPrinter)

'Preparate for the ESC/POS command.
lReturn = WritePrinter(lhPrinter, ByVal sControlString,
Len(sControlString), lpcWritten)

lReturn = EndPagePrinter(lhPrinter)
lReturn = EndDocPrinter(lhPrinter)
lReturn = ClosePrinter(lhPrinter)
common_exit:
Exit Sub
common_error:
Err.Raise Err.Number, THIS_MODULE, Err.Description

End Sub
'---------------------------------------------------------------------------
----
' Retrieves the cash drawer in XML format
'---------------------------------------------------------------------------
----
Private Function XML_CashDrawers_RetrieveForPop(ByVal CashDrawerID As Long)
As String
Const THIS_METHOD = "XML_CashDrawers_RetrieveForPop"

Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim oStream As ADODB.Stream
Dim oParam As ADODB.Parameter

On Error GoTo common_error

Set cmd = New ADODB.Command
Set oStream = New ADODB.Stream
Set oParam = New ADODB.Parameter
Set conn = New ADODB.Connection

With oParam
.Name = "ID"
.Direction = adParamInput
.Value = CashDrawerID
.Type = adInteger
.Size = 4
End With

conn.Open sBravoTempConnect
oStream.Open

With cmd
.ActiveConnection = conn
.Properties("Output Stream") = oStream
.CommandType = adCmdStoredProc
.CommandText = "XML_CashDrawers_RetrieveForPop"
.Parameters.Append oParam
.Execute , , adExecuteStream
End With

XML_CashDrawers_RetrieveForPop = oStream.ReadText()

oStream.Close
conn.Close

GetObjectContext.SetComplete

common_exit:
Set cmd = Nothing
Set oParam = Nothing
Set oStream = Nothing
Set conn = Nothing
Exit Function

common_error:
Set cmd = Nothing
Set oParam = Nothing
Set oStream = Nothing
Set conn = Nothing

Err.Raise Err.Number, THIS_MODULE, Err.Description

End Function

'---------------------------------------------------------------------------
----
'Pops open the cash drawer specified by vCashDrawerID
'---------------------------------------------------------------------------
----
Public Sub CashDrawer_PopDrawer(ByVal CashDrawerID As Long)
Const THIS_METHOD = "CashDrawer_PopDrawer"

Dim DOMDOC As DOMDocument
Dim oCashDrawerNode As IXMLDOMNode

Dim sXML As String
Dim sControlCode As String
Dim sPrinter As String

On Error GoTo common_error

Set DOMDOC = New DOMDocument

sXML = XML_CashDrawers_RetrieveForPop(CLng(CashDrawerID))

DOMDOC.loadXML sXML

Set oCashDrawerNode = DOMDOC.documentElement.childNodes(0)

With oCashDrawerNode.Attributes
sPrinter = .getNamedItem("sPrinter").nodeValue
sControlCode = .getNamedItem("sControlChar").nodeValue
End With

exec_POSCommand sPrinter, sControlCode

common_exit:
Set DOMDOC = Nothing
Set oCashDrawerNode = Nothing
Exit Sub

common_error:
GetObjectContext.SetAbort
App.LogEvent vbNewLine & THIS_MODULE & CStr(Err.Number) & vbTab &
Err.Source & vbTab & Err.Description & " Final Method: " & THIS_METHOD,
vbLogEventTypeError
Resume common_exit

End Sub



--
Justin Weinberg

Designing a PrintDocument? Drawing to forms?
Check out GDI+ Architect at www.mrgsoft.com
"Ioannis Demetriades" <id**********@yahoo.co.uk> wrote in message
news:ed**************@tk2msftngp13.phx.gbl...
Hi Justin,

What i am trying to do is to instruct a POS printer to open the cash drawer. The appropriate escape sequence is just a single character -the problem is
that i have to change the font of that char just before sending it. I've
tried it in VB6 and it works!.

Is there a way to substitute the changing of the font with a sequence of
characters?

Thanks
"Justin Weinberg" <jweinberg@_spamkill_mrgsoft.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
If I understand what you are doing - you are probably working with some

sort
of receipt printer and maybe trying to pop a cashdrawer or something to

that
effect. There should be codes associated with your printer that you can
send to it and do this

You'll need to go unmanaged to do this, and it's probably specific to that
printer to some degree, unless you are using some standard POS codes.
Instead of trying to set your font under windows to control, you'll want

to
send the appropriate escape char to set it.

Check out KB 322090:

http://support.microsoft.com/default...en-us%3B322090

--
Justin Weinberg

Designing a PrintDocument? Drawing to forms?
Check out GDI+ Architect at www.mrgsoft.com
"Ioannis Demetriades" <id**********@yahoo.co.uk> wrote in message
news:Oe*************@TK2MSFTNGP11.phx.gbl...
Hi,

I need to change the printer's font to "control" -a printer font, and

then send a sequence of characters to the printer. My problem is that I cannot change the printer's font. Can this be done without API calls?

Thanks
Ioannis



Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Anson Ng | last post by:
I found out that VB.Net supports only TrueType and OpenType fonts, in other words, it doesn't load printer fonts (device fonts) that are associated with a printer. I'm writing an application that...
5
by: Tom Berry | last post by:
We currently are trying our first transformation from VB6 to VB.Net. Of course, the Printer object is gone, but I'm having trouble finding the replacement syntax necessary to perform similar...
1
by: Alejandra Parra | last post by:
In my code, I print a dataSet ' get grid's PrintDocument object Dim pd As System.Drawing.Printing.PrintDocument pd = flexgrid.PrintParameters.PrintDocument() ' set up the page (landscape, 1.5"...
4
by: Salad | last post by:
I'm developing an app where the print output will be on a dot-matrix printer. I suppose the printers will either be an Epson or Okidata, not really sure at this point. I, unfortunately, do not...
3
by: Alejandra Parra | last post by:
In my code, I print a dataSet ' get grid's PrintDocument object Dim pd As System.Drawing.Printing.PrintDocument pd = flexgrid.PrintParameters.PrintDocument() ' set up the page (landscape, 1.5"...
2
by: dever | last post by:
I checked my color printers's Printersettings.SupportsColor, which all showed false. What is wrong that I could not use this property. Also, what other way to detect if a printer is color...
3
by: Michael | last post by:
Hi, I'm trying to print barcodes to the Dymo LabelWriter printer. Put everytime I send a job to the label printer it just outputs an empty label. If I change the default printer back to the...
0
by: John | last post by:
Hi I did a report a while ago set to Epson LQ-1050 and using the hardware fonts to speed up printing. Recently I had to make some changes to report but the problem is that the hardware printer...
3
by: John | last post by:
Hi I have a report for which I have set the Epson LQ-1050 (dot matrix) as the default printer. The problem is that I still can't see the printer's native (hardware) fonts in the font selection...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.