Forum OpenACS Q&A: Printing with printer control fonts from HTML

Hi all.

Not really appropriate to OpenACS Q&A, but I'm hoping for some help in the spirit of the original Web/DB! Nobody else can seem to help me.

I've got an electronic till cash drawer attached to an Epson thermal (receipt) printer. The opening of the cash drawer is controlled by printing a certain letter in a certain Control font to the printer. This works fine as per the manual when I'm printing from Microsoft Word or Wordpad. My problem is trying to do this from HTML. I select my thermal printer (this should make the control font available), open and print a simple web page that looks like this:

<html>
<head>
</head>
<body>
<FONT FACE="control" size="10">A</font>
</body>
</html>

Instead of interpreting this as a control font command and passing it on to the cash drawer, the printer just prints out the letter A (which is one of my favourite letters, but not quite what I want to see coming out of my receipt printer!)

One of the guys here in the office said that the problem is that browsers print an image of whatever's on the page to the printer, rather than sending the actual page content. Is this true?

I had a brief and unhelpful chat with Epson's technical support? They had no idea how to print the control font from HTML, said they'd get back to me and never did. 😟

Can anyone suggest a way I might achieve this? Any useful 3rd party products that I could look at? I've got a pretty ugly workaround using Scriptx from meadroid.com which involved opening MS Word and printing from there. Yack!

Cheers,
Brian

Collapse
Posted by MaineBob OConnor on
Brian, What are you "really" getting by printing the "A".
Maybe it is JUST a Lovely "A".  I assume that printer control codes are ESCaped or something.  What does the "Control" font
show exactly?

-Bob

Collapse
Posted by Brian Fenton on
Hi Bob,
thanks for the reply. I'm not sure I fully understand your question. Are you asking me what the printer "sees" when the letter A is sent to it using the control font? If so, I'm afraid I don't know the answer to that. Is there an easy way of seeing that? In terms of what I see, I have a Word document with the letter A, I have my printer defaulted to my Epson thermal printer and my chosen font is "control". So it looks like any other Word document. I only get the control font in my list of fonts when I select the thermal printer.

I tried saving the Word document as RTF and opening it in a text editor (Textpad) and printing from there, but that just prints the A, instead of opening the till drawer. I don't know  how to preserve the font information in a text format.

Brian

Collapse
Posted by Patrick Giagnocavo on
Brian, I think that you should try to narrow down what is happening a little more.

Can you print any other characters in the Control font, like a cents sign, or something that should print a character on the paper?  That is the first test to determine whether the font is being used by the web browser.

Collapse
Posted by Brian Fenton on
Hi Patrick,
thanks for the reply. Yes, I've narrowed it down a little bit more since. It appears the browser (IE 5.5 on Windows 2000) can't seem to see that font. The following page displayed the letter A using fantasy font (it ignored the contol font):

<html>
<head>
</head>
<body>
<FONT FACE="control, fantasy" size="9.5">A</font>
</body>
</html>.

I tried using a media=print style as follows but that too printed in the fantasy font when I printed the page out:

<html>
<head>
<style>
h1 {
  font-size : 9.5pt;
  font-family : fantasy;
}
</style>
<style media="print">
h1 {
  font-size : 9.5pt;
  font-family : control;
}
</style>
</head>
<body>
<h1>A</h1>
</body>
</html>

I've also since verified that text is indeed printed as text, not as an image as I originally thought.

Any other suggestions?

Collapse
Posted by Jeff Davis on
Brian, have you tried printing to a file and
seeing if you can put the literal codes sent
to the printer in the page?

My guess is this won't work either but it's worth a try...

Collapse
Posted by Brian Fenton on
Hi Jeff,
Yes I've tried that. I just get a print-out of gibberish.

I think the key to the problem is persuading IE to use the control font. Any idea how I might do that?

Collapse
Posted by David Siktberg on
Do you have an option of sending the required control codes directly to the printer?  The printer manual should explain what character sequences invoke the control font.  Then use the HTML ASCII character representations ( &#xxx; ) to create the required control characters to invoke and revoke the control font.
Collapse
Posted by Brian Fenton on
Hi David,
Thanks for the feedback. Yes, I already considered that. There are 2 problems with that:  firstly, the manual doesn't explain any of that kind of detail. It simply says to select the control font and print that. I've tried printing to file, saving as text, anything else I could think of, but I can't extract that kind of information. The second problem with that is HTML only permits 3 control characters: Horizontal tab, line feed and space, so even if I knew the characters, I've no guarantee HTML will be able to print them.

I've been scouring the web all week. I don't understand much about fonts (or Windows programming in general) but there seems to be almost no information out there about how browsers handles fonts, specifically printer fonts. Odd.

Collapse
Posted by David Siktberg on
I think this is the track you need to pursue, so hang in there.

The changing of fonts when you print from Windows / IE will be effected by a combination of Windows, the printer driver for this printer, and IE.  In the end, a few special ASCII characters will be shipped to the printer telling it to switch to "control font" and interpret the subsequent received characters as action directives instead of characters to print on the printer.  Another control sequence will return to regular printing.

You really need to find this control character sequence.  There must be a way to inspect the printer driver to see what it does to invoke fonts, but I am unaware of how to do so.  So you need to rely on printing a very small Word file (that includes identifiable conventional text before and after the control font character) to a file and inspecting it with a hex editor is the way to determine the control character sequence used.  (It sounds like you've done this already.)  I can help you examine the file if you send it to me.  Shame on Epson for not prividing the details!

When we figure out the sequence required, we can then play with making it happen in HTML.

Collapse
Posted by Brian Fenton on
David, thanks for all your support! Ok, I've posted some files on the web at http://www.quest.ie/brian/ I'm not really up on reading hex, so I'd definitely appreciate some help here. What do you think?
Collapse
Posted by Ash Argent-Katwala on
It may be worth a try returning the page as "Content-Type: text/plain" with the appropriate ascii characters as bytes directly, and print that. I'm guessing this will sidestep much of the fun translation IE may do on your behalf.
Collapse
Posted by David Siktberg on
Great!  Section 4.3 in the printer manual says the special functions can also be invoked by single special characters without using the control font, IF you are not using an "Extended" font.  Is the regular font you are using Extended? (see the list in 4.1)  Character 81H corresponds to the control font A, and will open the drawer.  81H=129 decimal or &#129; , which by my O'Reilly HTML reference is not supported, but give it a try anyway.  You might also try &#131; which is supported in HTML, and is also defined as a drawer-opening command.

There is more relevant stuff in the documentation that I haven't read in detail, but let's try this now.  If it doesn't work, we can probe further.

Collapse
Posted by Brian Fenton on
Hi Ash. Tried that already. No joy. 😟

David,
yes I already tried one of the other non-Extended fonts (10cpi). Again the problem appears to be that IE can't see the printer fonts.

I think your other idea about which ASCII characters tell it to switch to the control font is worth chasing.

Thanks for the suggestions!

Collapse
Posted by David Siktberg on
The manual seems to say that you do not need to use the control font if you use the special characters like 81H.  If so, you needn't worry about IE and fonts to resolve this.

It might help for you to drive the printer / till directly without Windows in the picture (got an old DOS machine?) and learn what character sequences actually make the unit do what you want.  Then step two is to make Windows / IE generate that sequence.

Collapse
Posted by Allan Regenbaum on
I created a printable view of an html page and embedded these to force a page break .. maybe this will set you in the correct direction ....

append header "<p STYLE=\"page-break-before: always\">

im sure there are many other printer centric stylesheet settings ?

Collapse
Posted by Brian Fenton on
Ah yes David, I see what you're saying now. My reading of the manual was that you could only use the 81H with non-extended printer fonts. If I understand you correctly, you seem to be saying that the 81H should work with ANY font. Well, I'll give it a whirl!

DOS machine? I wish!

Allen, thanks for your suggestion. I'll look into it.

Brian

Collapse
Posted by Brian Fenton on
No joy with that either, David. It still only prints gibberish from the printer.

Allen, I had a look at some of the CSS2 tags you mentioned. I couldn't see anything about fonts though. Thanks for the help anyway.

I've pared in a binary editor the print file Word created down to the minimum size that still opens the till drawer (when I copy it to LPT1 from a Windows command prompt). It's only got 5 characters! I've posted it up here: http://www.quest.ie/brian/test3.prn
Any ideas how to convert that to something the browser can use?

I got an interesting suggestion from another source. He said:
"you could try configuring the browser's monospace font (or one of the weird ones like cursive or fantasy) to be the control font, and then change the HTML to use the monospace font.  Of course, if you need the monospace font for something else this won't help.  I have a feeling though, that if it won't use the control font by name, it probably won't let you use it as a 'special' font. Perhaps the font is a raster font or something and the browser ignores raster fonts."

When I asked him how I might do this, he never replied! Does anyone know how to configure the browser (IE 5.5 and 6.0) like this?

Collapse
Posted by David Siktberg on
Took a detailed look at the manual and at your five-byte file.  Cannot reconcile the five-byte file to the manual - the manual does not describe how the printer works (what characters produce what effects), but rather how the driver works.  Can you get a printer manual?  Anyway, it contains "Esc F 00H DC3 EOF".  DC3 has a standard ASCII "meaning" of Device Control 3 (look at ASCII values at http://www.asciitable.com), so perhaps that is what causes the drawer to open.  It's wierd that there is no "A" in there - probably means that control font sends out these characters when it encounters the letter A - i.e. the printer does not have a control font embedded in it.  Brick wall here unless you get something that describes how the printer responds to characters sent to it.  Probably not useful anyway because you cannot embed an Esc into your html.

The manual revealed more info on a closer reading.  The special characters 81H etc. appear not to work if you choose a "xxx cpi" font (see Sheet 17).  There are two native printer fonts (Printer Font Small and Large) (Sheet 11) that should let 83H through.  So try putting into your html something like <span style='font-family:Printer Font Small'>&#131;</span> and see if that works.

You might also poke into the printer driver files to learn how they control the printer, which might give you some insights.  I found the printer driver files on my Windows 2000 under \WINNT\system32\spool\drivers\w32x86\*.  The *.gpd files are text files that control printer functions other than fonts - explore those.  Your drivers are probably named Tm* (Sheet 22).

Good luck!

Collapse
Posted by Brian Fenton on
David,
I've decided not to put any more time into this problem. The work-around will have to do. Many, many thanks for all your time and efforts. I hope I can re-pay the favour some time.

Brian

Collapse
Posted by Michael Hinds on
Having got as far as having the correct sequence of characters to open the drawer, it was just a case of how to send a file directly from the web server to the printer (without IE corrupting it). We have a captive audience, so we have the luxury of being able to fiddle with OS settings. I personally have the added advantage of sitting across the room from Brian so I know this works :) Assuming a Windows 2000 environment with the printer set to be the default, here's what to do:
    1. Put the binary file containing the control chars under the page root somewhere. Give it a .till extension.
    2. On the client PC, create the file c:\snozone\print.bat with the contents:
      copy %1 lpt1
    3. On the client PC, associate .TILL files with the batch file. To be pedantic:
      • In Windows Explorer, click on Tools -> Folder Options...
      • Click on the "File Types" tab
      • Click "New"
      • Type .TILL as the file extension then click "OK"
      • This should appear in the list of registered file types and should be highlighted.
      • Click "Advanced"
      • At the top, change the name from FT00000n to TillDrawerOpener
      • Untick "Confirm open after download"
      • Click "New..."
      • Enter Print as the action
      • Enter c:\pathtofileyoucreated\print.bat "%1" as the application used to perform action
    4. Say the magic words "Open sesame" while requesting the file in IE. You should very briefly see the download dialogue and a command prompt flash on the screen, and the till drawer will open.
    5. It's easy enough to call this from JavaScript in a new window or a hidden frame.
Collapse
Posted by Mario Gonzalez on
I am having the same problem. I have managed to open the drawer from vb.net copying the file to the printer but can't open it from a web page... does anyone have the CONTROL.TTF file? Does anyone have a solution?

Marck

Collapse
Posted by hardy the on
i just got same probelm here.
i indirectly got my "control" Font. as brian says
WE can get control font if we set our default printer to pos printer. i use tm-u220b.

brian and others.
epson use character out side from writeable ascii.
so we almost can't use any writed text to control the printer function such as cut partial or other function.

i use comport tool kit which can send hex character.
for example i can cut partial if i send 1B 69 (in hex)

try communication tool program to send hex character.

and there is other trick to use normally word pad to send character under writeable ascii. it's by using control font which translate our font to unwriteable ascii (control character in ascii table).

i also got epson advance driver. now i will translate what is control font send to printer.

i will use cable from com 1 to com 2. then from com 1 i send control font. i rread from com 2 by comport tool kit to get it's hex value. if you have other snipper program to sniff com port, you don;t have to use any cable. just sniff it.

comport tool kit will give ablility to sniff but with limited periode. i already expired.

good luck
hardy
jakarta
indonesia
PS: we can discus diectly to  mailto:hardythe@cbn.net.id

Collapse
Posted by zeko tomic on
I have a similiar problem.
I need to use printer font for fast reciep printing,
but under .net i cannot assign the font becouse it is not ttf. I can see those fonts in word pad, but i gues that in .net only ttf can be assigned.
In vb6 and good old printer object everything works fine.
printer.fontname="control"
printer.print "P"
and cash door opens
good old vb6 :(
Collapse
Posted by Hiten Patel on
Try printing the character that is represted by ascii value of controls characters. To do this first find out what is ascii value of "Ctrl + A" and then use chr(XXX) function to get character represted by that value and then print this value.
Collapse
Posted by Javier Oltra on
It has been said here that someone has managed to open the drawer in VB.Net, I've spent some weeks trying to do it but I can't, i need to know how have you managed to do it, thnak you in advance.
Collapse
Posted by Brian Madden on
I found a way to do this directly from HTML using VBScript:

1. Identify the control code that will open the cash drawer, for me this worked by opening a DOS Command prompt and typing "echo ^[p0>lpt1" (my open code is ESC p 0 for an Epson TMU200D connected to LPT1.)

2. In VBScript, use the FileSystemObject to "write" this command to LPT1 as follows:

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objPrint = objFS.CreateTextFile("LPT1:", True)
objPrint.Write(Chr(27) & "p0")
objPrint.Close

3. From your HTML page, execute this script, either onLoad or via button push.

4. Experience joy as the drawer opens!

Hi Brian

The info was pretty needful. Am looking out for printing image, through thermal printer.

Am using ATP-80K printer.

Text printing works very fine. This printer is connected to COM port and not LTP1.

Collapse
Posted by desmond hew on
HI Lakshmikanth
"Text printing works very fine. This printer is connected to COM port"

i have the problem on printing the text to Epson thermal printer(slow printing) where im using php for my system..
Is there anyway to set the printer font at html?

kindly anyone please help

Collapse
Posted by Mark LePine on
Hi Brian

I've got an Epson TM5000II connected on LPT1. The DOS command "echo ^[p0>lpt1" does instantly pop open my cash draw. I can't get your FileSystemObject code to work however. I'm trying to get my cash draw to pop open when I complete a shop transaction on my POS software which is web based. I'm using IE 7. When I put the code into my page all I get is a 'File Not Found' error on the 'Set objPrint = objFS.CreateTextFile("LPT1:", True)' line.

Sorry to be a div but I don't know how to 'execute this script, either onLoad or via button push' part so I simply slotted the code into my page header, which is why I probably get this error. Perhaps you can explain a bit further how to execute this code using OnLoad. If the draw popped open when the page loads it would be ideal.

Regards

Mark

Collapse
Posted by Roger Smeds on
If all you are trying to do is open a cash drawer, I think I found something that may work for you. I spent several days researching this to no avail, although several solutions are posted in this forum. It occurred to me that the process ought to be much more simple than some of the approaches mentioned here. What worked was to specify a separator page in your receipt printer setup. This is sent to the printer just prior to the print job. The only thing in the separator page file is the hex commands to open the drawer. For my Epson TM-U200 (emulated) receipt printer the hex codes are 1b 70 00 19 ff. There is a good discussion of what is required to create a custom separator page at http://support.microsoft.com/kb/102712 Basically you create a file in something like notepad that has the following in it and nothing else. The first character defines what is an escape character. @ @H1b @H70 @H00 @H19 @Hff I placed each of the codes on a single line followed by a carriage return (the first character as well). Save the file with a .sep extension to the Windows - System32 directory, then specify the file as the separator page in your printer setup. Every time you send a print job to the receipt printer, the cash drawer will open. It sounds like you can use this process to set other printer control codes if necessary, but I haven't tried that. I just wanted the drawer to open.