Scalabium Software

SMExport advertising
Knowledge for your independence'.
Home Delphi and C++Builder tips


#87: How can I send a command strings to printer?

Sometimes useful to control a printer using direct command strings. It's a "DOS"-style but for some tasks this method is very useful.

For example, the Epson or HP printers have a lot of internal commands which allows to change a mode of printer, define the some parameters etc.

The everybody who tried to convert the DOS-programs from Pascal to Windows/Delphi, knows that the next statement

 WriteLn(lst, Chr(27) + '&l12D')

don't work in Windows. You must use the Escape function to send data directly to the printer.

View the example code which allows to send a command to printer:

type
  TPassThroughData = record
      nLen: Word;
      Data: array[0..255] of Byte;
  end;

procedure PrintText(s: string);
var
  PTBlock: TPassThroughData;
begin
  PTBlock.nLen := Length(s);
  StrPCopy(@PTBlock.Data, s);
  Escape(Printer.Handle, PASSTHROUGH, 0, @PTBlock, nil);
end;

procedure PrintOut;
begin
  Printer.BeginDoc;
  PrintText(#27'&l12D' + 'Hello, World!');
  Printer.EndDoc;
end;


Published: July 3, 2000

See also
 
SMMsg suite
Paradox Password Recovery
Paradox to MS Access converter
ABA Document Convert
SMDBGrid
SMImport suite
DBISAM Viewer
ABA Picture Convert
SMReport
Excel Web-stream
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2024, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport advertising