Scalabium Software

SMExport/SMImport suites
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
Paradox ActiveX
Clarion to Text converter
Paradox to Text converter
ABA Picture Convert
Paradox to MS Access converter
Mail parser (ActiveX)
SMExport suite
Protected Storage Viewer
Word Web-stream
Excel Reader (dll)

Contact to webmaster


Borland Software Code Gear Scalabium Delphi tips

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

SMReport Autogenerated