• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1361
  • Last Modified:

Print Graphic and Text to Epson TM-T88v

Hello Experts;

I need a solution to print a logo at the top of a receipt printed from an Epson TM-T88V printer. I've attempted to use examples for ESC/POS from the net without any success including writing various ESC commands to the printer port. Currently I'm writing the receipt data to a text file and sending it to the printer as text and re- writing the text file to the printer port.

The following is a simplistic approach that doesn't work because the printer cuts the paper off after the logo prints with the 'EndDoc' command...

procedure TForm1.Button7Click(Sender: TObject);
var
  Port: System.Text;
  Bitmap: TBitmap;
  F, F1: TextFile;
  Lines: TStringList;
  Index: Integer;
begin
  BitMap:=TBitmap.Create;
  BitMap.LoadFromFile('C:\MSRMS\LOGO2.bmp');
  with Printer do
  begin
  BeginDoc;
  Canvas.Draw(25,0,BitMap);
  EndDoc;
  try
  Lines := TStringList.Create;
  Printer.Canvas.Font.Size := 10;
  Lines.LoadFromFile('Receipt.txt');
  AssignPrn(F);
  Rewrite(F);
  for Index := 0 to Lines.Count-1 do
  Writeln(F, Lines[Index]);
  CloseFile(F);
  finally
  Lines.Free;
  BitMap.Free;
  end;
  end;
end;

Help with either an ESC/POS solution or printing text and graphic together using TPrinter would be greatly appreciated.

Thank you,
Visionet
0
visionetv
Asked:
visionetv
1 Solution
 
Geert GruwezOracle dbaCommented:
you are printing 2 sheets
first with a logo
second with the text

you'll have to use the first method to print the whole document if you als want text left or right of the logo
usually such printer cuts the sheet after each document

EndDoc and CloseFile indicate to the printer the document is finished

you'll have to scale everything you print
look for Delphi TPrinter BeginDoc EndDoc in google and you'll find multiple solutions
they usually all start with inquiring for the paper size and calculating the scale and font sizes to use
http://wiki.freepascal.org/Using_the_printer
http://www.festra.com/wwwboard/messages/2266.html
http://mc-computing.com/languages/delphi/Printing.html

there is a lengthy discussion here too:
https://www.experts-exchange.com/questions/10135477/Printer-Canvas-Scaling-And-Resolution.html

efg has an extensive page of links too:
http://www.efg2.com/Lab/Library/Delphi/Printing/index.html

it takes a bit of work to print everything nicely
you could create bitmap first and then stretch it to the printer canvas
like in the first freepascal link
0
 
Dr. KlahnPrincipal Software EngineerCommented:
I looked into a similar problem some years back.  In that situation the problem was being caused by the unwanted insertion of an FF (form feed) character after sending the graphics.  I suspect you're going to find that a similar issue is causing the unwanted form eject.  If that's the case, it might be workable to programmatically merge the header and the text into one file, then spool that file.
0
 
Sinisa VukCommented:
I work with Epson TM-T88 a lot....Will send example but not before Monday...
In short - I use Epson Opos engine to print receipts...Your way is printing as graphics... and this is so slow.... Using ESC codes and com port component is a much better....
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
visionetvAuthor Commented:
Hi Sinisa;

Please send the ESC example on Monday for the T-88 that is how I want to access the printer.

Thanks,
Visionetv
0
 
Sinisa VukCommented:
Ok, little later....
First, I define bitmap data in a printer and then start print buffer...
const ESC_ESC             = #$1B;
const ESC_FS              = #$1C;
const ESC_GS              = #$1D;

function BmpFileToDataList(sLogo: String; var xL, xH, yL, yH: Integer): String;
var
  Graphic: TGraphic;
  c: Byte;
  bmp: TBitmap;
  x, y, w, h, i: Integer;
begin
  Result := '';
  xL := 0;
  xH := 0;
  yL := 0;
  yH := 0;
  try
    bmp := TBitmap.Create;
    try
      bmp.PixelFormat := pf24bit;
      bmp.LoadFromFile(sLogo);
      bmp.Monochrome := True;
      bmp.PixelFormat := pf1bit; //convert to two color

      w := (bmp.Width div 8);
      if (bmp.Width mod 8) > 0 then Inc(w);
      w := w * 8;
      h := bmp.Height;

      xL := w mod 256;
      xH := w div 256;
      yL := h mod 256;
      yH := h div 256;

      //iterate pixels
      for y := 0 to h-1 do
      begin
        for x := 0 to (w div 8)-1 do
        begin
          //pack 8 x 1 pixel bits into one byte
          c := 0;
          for i := 0 to 7 do
          begin
            if (x * 8 + i) < bmp.Width then
            begin
              if Cardinal(bmp.Canvas.Pixels[x * 8 + i, y]) = 0 then  //is black?
                c := c or (1 shl (7-i));  //shift pixels into byte
            end;
          end;
          Result := Result + char(c);
        end;
      end;
    finally
      bmp.Free;
    end;
  except
    Result := '';
  end;
end;

procedure TForm1.Button12Click(Sender: TObject);
var
  sData, sCmd, sReaded, sPrnCmd: String;
  xL, xH, yL, yH, m, ln, p1 ,p2, p3, p4: Integer;
begin
  //bmp > nibble
  sData := BmpFileToDataList('C:\test.bmp', xL, xH, yL, yH);    
  //check if bmp data is valid
  if (Length(sData)> 0) and (xH <= 255) and (yH <= 8) then
  begin
    (*
    m     Mode
    0, 48 Normal
    1, 49 Double-width
    2, 50 Double-height
    3, 51 Quadruple
    *)
    m := 48;
    ln := 10 + Length(sData);
    p1 := (ln mod 256);
    p2 := ((ln div 256) mod 256);
    p3 := ((ln div 65536) mod 256);
    p4 := ((ln div 16777216) mod 256);

    //init
    sCmd := ESC_ESC + '@';

    {
    n	    Justification
    0, 48	Left justification
    1, 49	Centered
    2, 50	Right justification
    }
    //centered:  ESC	   	a	   	n
    sCmd := ESC_ESC + 'a' + Char(49);
    
    //define bmp data: GS 8 L p1 p2 p3 p4 m fn a bx by c xL xH yL yH d1...dk
    sCmd := sCmd + ESC_GS + '8' + 'L' + Char(p1) + Char(p2) + Char(p3) + Char(p4) + Char(m) +
      Char(112) + Char(48) + Char(1) + Char(1) + Char(49) + Char(xL) + Char(xH) + Char(yL) + Char(yH);

    //print: 	GS 8 L p1 p2 p3 p4 m fn
    sPrnCmd := ESC_GS + '(' + 'L' + Char(2) + Char(0) + Char(m) + Char(50);

    DirectPrintToCom('COM1', br38400, sCmd + sData + sPrnCmd, sReaded);
  end;
end;

Open in new window


I use TComPort component thnx to Dejan Crnila (created runtime)
Note: printing this way is a little slow ... data must be transferred all time. For printing logos you can use NV defined bitmaps (always stored in a printer)
Common text is printing by simple sending to com port.
   ..
    DirectPrintToCom('COM1', br38400, 'My text', sReaded);

Open in new window

For bolding, justifying ... use ESC commands for a chars...
0
 
visionetvAuthor Commented:
Hi Sinisa;

Thank you for the example. Using the code in my question I can print the logo and text but the printer cuts the paper after the logo is printed and then prints the text. As an alternative I stored the logo on board the T-88V but I can't figure out how to implement the ESC command in Delphi for printing the logo first then the text directly to the printer's virtual USB port.

I need to print the logo first either stored or directly and then the receipt text as a single sheet.

Visionet
0
 
visionetvAuthor Commented:
Hi Experts;

My need is to print a logo stored in non-volatile memory (NV) onboard an Epson TM-T88V receipt printer together with transaction data stored in a text file. The ESC/P commands in the Epson developer guide are listed as ASCII, Hex, or Decimal. According to my research the commands need to be converted to 'AnsiStrings' to be Delphi compatible for sending instructions to the printer

For example, the ESC/P ASCII 'cut paper' command listed in the Epson manual is '#GS V 0' which converts to AnsiString 'CHR($1D)+'V'+CHR(0)' for use in Delphi which I have tested and it works.  The ESC/P ASCII command for printing the content of the printer's NV is 'GS(L <function 69>) which I do not know how to convert to an AnsiString.

Another possible approach is using the ESC/P (Escape) functions in the WinAPI and call ShellExecute() to send to the printer. I haven't yet determined what the ESC/P command syntax and structure need to be to use the WinAPI as an alternative.

Any help, direction, or comments will be greatly appreciated, I've been stuck on this issue for several days.

Thank you,
Visionet
0
 
Sinisa VukCommented:
i will produce example in a few days...sorry very busy these days...
Under which key id you stored logo in NV memory?
0
 
visionetvAuthor Commented:
Hi Sinisa;

Thank you that would be great. Key id is 48,49 "01".
0
 
Sinisa VukCommented:
For a additional info about print NV logo with Function 69 go here...and for setting NV logo (but you've done that - go here...)

(with help of my functions to send data to com port...)
var
  sReaded, sPrnCmd: String;
  m: Integer;
  kc1, kc2: Integer;
begin
  //Print the specified NV graphics data - Function 69
  m := 48;
  kc1 := 48;
  kc2 := 49;

  //GS	   	(	   	L	   	pL	   	pH	   	m	   	fn	   	kc1	   	kc2	   	x	   	y
  sPrnCmd := ESC_GS + '(' + 'L' + Char(6) + Char(0) + Char(m) + Char(69) + Char(kc1) + Char(kc2) + Char(1) + Char(1);

  DirectPrintToCom('COM8', br38400, sPrnCmd, sReaded);

Open in new window

0
 
visionetvAuthor Commented:
Thank you for the example. I overlooked the settings in the 'Document Settings' of the TM-T88V 'Printing Preferences' which also provides control over the NV onboard graphics.

Thanks again for the help,
Visionet
0
 
Sinisa VukCommented:
You're welcome...
I use OPOS drivers...So I code once and work with most different printers...and simplify printing becouse there are no ESC commands, just simple functions to call...
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now