使用如下过程:
procedure WriteToPrinter(PrinterName: string;
S: string);
//PrinterName: 打印机名字及EPSON LQ-1600K等,S为打印机的ESC命令等。
var
Handle: THandle;
N: DWORD;
do
cInfo1: TDocInfo1;
begin
if not OpenPrinter(PChar(PrinterName), Handle, nil) then
begin
ShowMessage('error ' + IntToStr(GetLastError));
Exit;
end;
withdo
cInfo1do
begin
pDocName := PChar('直接打印测试');
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;
如打印换行为:
WriteToPrinter('EPSON LQ-1600K', #13 + #10);
//#13 为十六进制 OD