首页  编辑  

直接打印字符串到打印机

Tags: /超级猛料/Print.打印/   Date Created:

直接打印字符串到打印机

uses WinSpool;

procedure WriteRawStringToPrinter(PrinterName:String; S:String);

var

  Handle: THandle;

  N: DWORD;

  DocInfo1: TDocInfo1;

begin

  if not OpenPrinter(PChar(PrinterName), Handle, nil) then

    begin

     ShowMessage('error ' + IntToStr(GetLastError));

     Exit;

    end;

  with DocInfo1 do begin

    pDocName := PChar('test doc');

    pOutputFile := nil;

    pDataType := 'RAW';

  end;

  StartDocPrinter(Handle, 1, @DocInfo1);

  StartPagePrinter(Handle);

  WritePrinter(Handle, PChar(S), Length(S), N);

  EndPagePrinter(Handle);

  EndDocPrinter(Handle);

  ClosePrinter(Handle);

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

 WriteRawStringToPrinter('HP', 'Test This');

end;