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:

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

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

procedure PrintOut;
  PrintText(#27'&l12D' + 'Hello, World!');

Published: July 3, 2000

See also
SMExport suite
Viewer for TNEF-files (winmail.dat)
dBase Viewer
ABA Spreadsheet Convert
Database Information Manager
Excel Web-stream
ABA Document Convert
Fast Document Viewer
ABA Picture Convert

Contact to webmaster


Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2021, Scalabium Software. All rights reserved.

SMExport advertising