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
Viewer for TNEF-files (winmail.dat)
Database Information Manager
ABA Document Convert
ABA Database Convert
ABA Picture Convert
Fast Document Viewer
SMMsg suite
Clarion Viewer
Paradox to Text converter
Paradox to MS Access converter

Contact to webmaster


Borland Software Code Gear Scalabium Delphi tips

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

SMExport advertising