Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Sending raw codes to receipt printer


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 6 - Last Post: May 24, 2015 1:54 PM Last Post By: Markus Humm
Jim Duskes

Posts: 8
Registered: 6/15/15
Sending raw codes to receipt printer  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 19, 2015 10:11 AM
I'm converting a 20 year old, ticket-selling app from Windows to OSX. It was developed in Delphi 6 and I've now transferred it to FMX in XE7. It all works fine, except for the printing. The client I'm doing this for wants the receipt printed in the exact same format and font as the Delphi 6 version. In that version I sent ESC/POS codes directly to the printer and used the built-in fonts. In the current XE7 version, I'm 'drawing' the text on Printer.Canvas and then sending it to the printer. The code below works fine. However, I've been unable to match the font and character spacing exactly and the client is not happy. I've now installed a CUPS RAW printer driver on my OSX machine following the instructions at https://code.google.com/p/jzebra/wiki/TutorialRawOSX. However, I can't seem to find a way to send the raw codes to the printer. I've tried such things as AssignPrn, but checking the source code, it also draws to Printer.Canvas. I've tried looking for the printer 'file', /dev/lp0, or its equivalent in OSX, but no luck. I've searched Google for hours. Any help would be appreciated.

Thanks!

The client wants the receipt displayed on-screen before printing. I use a TMemo and print with the following code
  Printer.ActivePrinter;
  Printer.Canvas.Fill.Color := claBlack;
  Printer.Canvas.Fill.Kind := TBrushKind.Solid;
  Printer.Canvas.Font.Family := ReportMemo.Font.Family;
  Printer.Canvas.Font.Style := [TFontStyle.fsBold];
  Printer.Canvas.Font.Size := 12;
 
  Printer.BeginDoc;
  Printer.ActivePrinter.SelectDPI(72, 72);
  Printer.NewPage;
 
 Printer.Canvas.Font.Size := 12;
 
  Y := 0;
  for X := 0 to ReportMemo.Lines.Count - 1 do
  begin
    Y := (X * 12) + 10;
    Printer.Canvas.FillText(RectF(0, Y, 212, Y+12), ReportMemo.Lines[X], True, 1, [], TTextAlign.taLeading, TTextAlign.Center);
  end;
  Printer.EndDoc;
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Sending raw codes to receipt printer  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 19, 2015 1:39 PM   in response to: Jim Duskes in response to: Jim Duskes
Hello,

did you already look at this one:

https://code.google.com/p/jzebra/wiki/TutorialAPI

In that Java code you can see they use

import jzebra.PrintRaw;
import jzebra.PrintServiceMatcher;

If you can get the source code for jzebra.jar you might be able to
figure out how to call this printer driver's API for raw commands.

Another thing: did you already look at Mac OS X documentation? I once
developped a Windows application which sends raw ESC/P commands and
there was some API in the Windows API to send raw commands. We then set
up the printer as a generic/text only printer.

Greetings

Markus
Jim Duskes

Posts: 8
Registered: 6/15/15
Re: Sending raw codes to receipt printer  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 19, 2015 2:29 PM   in response to: Markus Humm in response to: Markus Humm
Thanks Markus,

I was looking into that very example this morning and came to the same conclusion, but I wasn't able to find the code that did the actual sending.

Sending ESC/P commands from Windows is no problem, but porting that code to OSX doesn't work. But, you've given me some food for thought there.

Cheers!

Edited by: Jim Duskes on May 19, 2015 2:32 PM
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Sending raw codes to receipt printer [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 20, 2015 10:46 AM   in response to: Jim Duskes in response to: Jim Duskes
Am 19.05.2015 um 23:33 schrieb Jim Duskes:
Thanks Markus,

I was looking into that very example this morning and came to the same conclusion, but I wasn't able to find the code that did the actual sending.

Sending ESC/P commands from Windows is no problem, but porting that code to OSX doesn't work. But, you've given me some food for thought there.

Cheers!

Hi,

glad to be of help.

Greetings

Markus
Jim Duskes

Posts: 8
Registered: 6/15/15
Re: Sending raw codes to receipt printer  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 21, 2015 1:30 PM   in response to: Jim Duskes in response to: Jim Duskes
I've figured out how to send raw text to the printer but the ESC/P codes get filtered out. This is the code I'm using. Anyone have any ideas?

....
const
  libc = '/usr/lib/libc.dylib';
 
....
 
//Create a new stream connected to a pipe running the given command. Pipe output not used in this app; _system gives same results.
function popen(const Command: PAnsiChar; Modes: PAnsiChar): PIOFile; cdecl; external libc name '_popen';
 
....
 
procedure TMainForm.PrintBtnClick(Sender: TObject);
var
  PrinterDev: TPrinterDevice;
  PRNFile: TextFile;
begin
  PrinterDev := Printer.ActivePrinter;
  AssignFile(PRNFile, CurDir + '/10000001.prn');
  ReWrite(PRNFile);
  Write(PRNFile, #27#64#13#10#27#33#16 + 'THIS ROCKS!!!!' + #27#33#1#13#10);
  CloseFile(PRNFile);
 
  popen(PAnsiChar(AnsiString('lp -d ' + PrinterDev.Port + ' ' + CurDir + '/10000001.prn')), 'r');
end;
 


Edited by: Jim Duskes on May 21, 2015 1:30 PM
Jim Duskes

Posts: 8
Registered: 6/15/15
Re: Sending raw codes to receipt printer  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 21, 2015 2:55 PM   in response to: Jim Duskes in response to: Jim Duskes
Figured it out. For anyone needing to do this in the future:

1. forget about installing a raw printer queue in CUPS. As explained here, http://stackoverflow.com/questions/12271871/cups-bypassing-interface, there's no such thing! Simply install the regular printer driver for your printer.

2. in my code above, replace the popen line with:
popen(PAnsiChar(AnsiString('lp -d ' + PrinterDev.Port + ' -o raw ' + CurDir + '/10000001.prn')), 'r'); 


In other words, by including the -o raw option in the lp command, we tell the driver to treat all incoming data as text as simply pass it through to the printer unchanged.

Thanks for your help and listening to me think out load.

Cheers!

Edited by: Jim Duskes on May 24, 2015 1:53 PM
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Sending raw codes to receipt printer  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 23, 2015 5:43 AM   in response to: Jim Duskes in response to: Jim Duskes
Am 21.05.2015 um 23:55 schrieb Jim Duskes:
Figured it out. For anyone needing to do this in the future:

1. forget about installing a raw printer queue in CUPS. As explained here, http://stackoverflow.com/questions/12271871/cups-bypassing-interface, there's no such thing! Simply install the regular printer driver for your printer.

2. in my code above, replace the popen line with:
popen(PAnsiChar(AnsiString('lp -d ' + PrinterDev.Port + ' -o document-format=text/plain ' + CurDir + '/10000001.prn')), 'r'); 


In other words, by including the -o document-format=text/plain option in the lp command, we tell the driver to treat all incoming data as text as simply pass it through to the printer unchanged.

Thanks for your help and listening to me think out load.

Cheers!

Thanks for sharing your solution!

Greetings

Markus
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02