Jump to content
Sign in to follow this  
Calomix

Printing Bitmap in FMX with a Thermal Printer

Recommended Posts

Hi, I'm fairly new to Delphi and I'm trying to print a receipt along with a digital signature drawn on the phone. I turn the canvas vector into a bitmap but I can't seem to output the signature through the GO Link GL-28 printer. And since I'm new at this I'm using Chat GPT which is leading me to use Printer.Canvas.TextOut, Printer.Canvas.DrawText and Printer.Canvas.TextRect. None of which seems to work. I get the undeclared identifier on all three. how can I print the data I want?

 

procedure TModPrincipal.SendToPrinter(const AData: string);
var
  Printer: TPrinter;
  i, YPos: Integer;
  Rect: TRectF;
begin
  Printer := TPrinter.Create;  // Create a printer instance
  try
    Printer.BeginDoc;
    YPos := 10;

    for i := 1 to Length(AData) do begin
      Printer.Canvas.TextOut(10, YPos, AData);
      Inc(YPos, 20);
    end;

    for i := 1 to Length(AData) do begin
      Printer.Canvas.DrawText(10, i*20, AData);
    end;

    for i := 1 to Length(AData) do begin
      Rect := TRectF.Create(10, YPos, 200, YPos + 20);
      Printer.Canvas.TextRect(Rect, 10, YPos, AData);
      Inc(YPos, 20);
    end;

  finally
    Printer.EndDoc;
    Printer.Free;  // Free the printer after use
  end;
end;

 

 

Share this post


Link to post

 

Hi, 

Problem here seems you have not choosen a "target" printer.

Try something like bellow instead, in order to test. 

 

procedure TForm1.Button1Click(Sender: TObject);
var
 Destrect : TrectF;
begin
  //put a TPRinterDialog on the form
  //Put a Trectangle on the form...
  if PrintDialog1.Execute then begin //Execute a dialog where you can choose a printer.
      //print clicked. The code below will draw a rectangle on standart "A4"/letter us printer size. Please adapt.
      Setprinter(printer);
      Printer.Canvas.BeginScene;
        Printer.Orientation:=TPrinterOrientation.poPortrait;
        Printer.title:='Your title';
        Printer.ActivePrinter.SelectDPI(1200,1200);
        Printer.BeginDoc;
        var lval := Printer.PageWidth div 4;
        Destrect:=TRectF.Create(lval,lval,Printer.PageWidth-lval,Printer.PageHeight-lval);
        Rectangle1.Paintto(  Printer.canvas, Destrect );
        Printer.EndDoc;
      Printer.Canvas.EndScene;
  end;
end;

 

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×