Mega Code Archive

 
Categories / Delphi / Printing
 

How to Use PASSTHROUGH Escape to Send Data Directly to Printer

Title: How to Use PASSTHROUGH Escape to Send Data Directly to Printer type TPrnBuffRec = record bufflength: Word; Buff_1: array[0..255] of Char; end; function DirectToPrinter(S: string; NextLine: Boolean): Boolean; var Buff: TPrnBuffRec; TestInt: Integer; begin TestInt := PassThrough; if Escape(Printer.Handle, QUERYESCSUPPORT, SizeOf(TESTINT), @testint, nil) 0 then begin if NextLine then S := S + #13 + #10; StrPCopy(Buff.Buff_1, S); Buff.bufflength := StrLen(Buff.Buff_1); Escape(Printer.Canvas.Handle, Passthrough, 0, @buff, nil); Result := True; end else Result := False; end; // this code works if the printer supports escape commands // you can get special esc codes from printer's manual // example: printer.BeginDoc; try directoprinter('This text '); finally printer.EndDoc; end;