Link to home
Start Free TrialLog in
Avatar of formi
formiFlag for Switzerland

asked on

Delphi: how to send PJL commands to printer

Hi

I need to control a printer to staple or punch. For this I have to send PJL-commands to the driver. I found this code:
type
    TPrnBuffRec = record
      bufflength: Word;
      Buff_1: array[0..1000] of AnsiChar;
    end;

function DirectToPrinter(S: ansistring): Boolean;
var
    Buff: TPrnBuffRec;
    TestInt: integer;
    N : cardinal;
begin
  Printer.BeginDoc;
  TestInt := PassThrough;
  if Escape( Printer.Handle, QUERYESCSUPPORT, SizeOf(TESTINT), @testint, nil) > 0 then
  begin
    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;
  Printer.EndDoc;
end;

Open in new window

To test I call this function and print in a file
DirectToPrinter('HELLO');

Open in new window

I expect that I should find the sent text "HELLO" in this file but I don't. Where can be the problem?
Thanks, Peter
(the used printerdriver is a HP LaserJet M880 PCL 6)
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

You should use ESC commands to print out..... similar to this example, or this MS example...
There is a PCL language description for HP printers... which might help you...
Avatar of formi

ASKER

Thanks. I found that I have to add StartPage and EndPage. Now it works.
ASKER CERTIFIED SOLUTION
Avatar of DansDadUK
DansDadUK
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial