起先以为很难,其实还可以.参阅了DFW们的回答,像在DOS下一样,直接控制打印机完全可以,我用的是Star 2400打印机
方法1
procedure WriteRawStringToPrinter(PrinterName:String;
S:String);
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('testdo
c');
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);
var s:string;
begin
s:=#27#117+'2'+'中国人民24X16'+#10;
WriteRawStringToPrinter('Star 2400',#26#78+'字间距3'+#10);
WriteRawStringToPrinter('Star 2400',#26#81+'字间距0'+#10);
WriteRawStringToPrinter('Star 2400',#27#48+'行距1/6'+#10);
WriteRawStringToPrinter('Star 2400',S);
WriteRawStringToPrinter('Star 2400',#27#117+'1'+'恢复24X24'+#10);
WriteRawStringToPrinter('Star 2400',#27#50+'行距1/8'+#10);
WriteRawStringToPrinter('Star 2400',#26#81+'中国人民'+#10);
WriteRawStringToPrinter('Star 2400',#28#14+'横向放大'+#10);
WriteRawStringToPrinter('Star 2400',#27#118+'逆向走纸');
WriteRawStringToPrinter('Star 2400',#10);
WriteRawStringToPrinter('Star 2400',' 定位');
WriteRawStringToPrinter('Star 2400',#27#102);
WriteRawStringToPrinter('Star 2400',#10#10+'正常走纸'+#10);
WriteRawStringToPrinter('Star 2400',' 定位'+#10);
end;
方法2
procedure TForm1.Button2Click(Sender: TObject);
var
F: TextFile;
begin
AssignFile(F, 'LPT1');
Rewrite(F);
Writeln(F, #26#78+'字间距3');
Writeln(F, #26#81+'字间距0');
Writeln(F, #27#48+'行距1/6');
Writeln(F, #27#117+'2'+'中国人民24X16');
Writeln(F, #27#117+'1'+'恢复24X24');
Writeln(F, #27#50+'行距1/8');
Writeln(F, #28#14+'横向放大');
Writeln(F, #27#118+'逆向走纸');
Writeln(F, ' 定位');
Writeln(F, #27#102);
Writeln(F, #10#10+'正常走纸');
Writeln(F, ' 定位');
CloseFile(F);
end;